此方法使用浅拷贝克隆传递的对象。它将所有原始属性复制到结果中。
语法
object.clone();
返回值
返回对象的克隆。
例子
HTML
x
31
31
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function showResult() {
8
var o = { name: 'Prototype', version: 1.5, authors: ['sam', 'contributors'] };
9
var o2 = Object.clone(o);
10
o2.version = '1.5 weird';
11
o2.authors.pop();
12
13
alert( " Value of o.version : " + o.version );
14
// Returns 1.5
15
16
alert( " Value of o2.version : " + o2.version );
17
// Returns 1.5 weird
18
19
alert( " Value of o.authors : " + o2.authors );
20
// Returns ['sam']
21
}
22
</script>
23
</head>
24
25
<body>
26
<p>Click the button to see the result.</p>
27
<br />
28
<br />
29
<input type = "button" value = "Result" onclick = "showResult();"/>
30
</body>
31
</html>
阅读剩余 81%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8695.html