javascript原型式继承如何理解

1、说明

利用空对象作为中介,将某个对象直接分配给空对象构造函数的原型。

2、缺点

原型链继承多个实例的引用类型属性指向相同,可能会被篡改。

不能传递参数。

3、实例

varperson={
name:"Nicholas",
friends:["Shelby","Court","Van"]
};

varanotherPerson=object(person);
anotherPerson.name="Greg";
anotherPerson.friends.push("Rob");

varyetAnotherPerson=object(person);
yetAnotherPerson.name="Linda";
yetAnotherPerson.friends.push("Barbie");

alert(person.friends);//"Shelby,Court,Van,Rob,Barbie"
原文来自:https://www.py.cn
© 版权声明
THE END
喜欢就支持一下吧
点赞10 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片快捷回复

    暂无评论内容