如題,下面代碼里數(shù)組可以改變,但是函數(shù)卻無法改變: 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); //數(shù)組arr =[1,2,5,4,'hello']
既然函數(shù)也是引用類型,為什么原型繼承無法改變
30秒到達戰(zhàn)場
2018-10-11 17:11:38