想要用一个值来保存另一个值,如下:
var source=[1,2,3]
var des=source;
des[0]=5;
要怎么样,才能在修改des的时候,不改变source那?
大家讲道理2017-04-11 11:37:32
var source=[1,2,3]
var des=source.slice();
des[0]=5;
des
[5, 2, 3]
source
[1, 2, 3]
var obj = {a: 25, b: 50, c: 75};
var A = Object.create(obj);
A.a = 30;
console.log(obj.a + " " + A.a); // 25 30
if (!Object.create){
Object.create = function(proto) {
function F(){}
F.prototype = proto;
return new F;
}
}