您现在的位置是:课程教程文章
javascript原型式继承如何理解
2023-12-14 20:39课程教程文章 人已围观
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"
以上就是javascript原型式继承的理解,希望对大家有所帮助。更多Javascript学习指路:Javascript
课程教程:javascript原型式继承如何理解下一篇:没有了