如题,下面代码里数组可以改变,但是函数却无法改变:
var human = {
say:function(){
console.log("我是人类");
},
arr:[1,2,5,4]
}
human.say();
var people = Object.create(human);
people.say = function(){
console.log("我改变了他");
}
people.arr.push("hello");
people.say(); //输出的是"我改变了他"
var anotherPeople = Object.create(human);
anotherPeople.say(); //没有变化,还是"我是人类"
console.log(anotherPeople.arr); //数组arr =[1,2,5,4,'hello']
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…