摘要: 6种继承方式: 1.原型链继承2.借用构造函数(经典继承)3.组合继承4.原型式继承5.寄生式继承6.寄生组合式继承 1.原型链: 缺点:所有实例会共享属性 新实例无法向父类构造函数传参 function FirstProto() { this.name = 'xiaoming'; this.col 阅读全文
posted @ 2018-04-19 12:15 sunmarvell 阅读(143) 评论(0) 推荐(0) 编辑
摘要: 寄生式继承 函数不能复用,降低效率,但新对象不仅具有person的属性和方法,还有自己的方法。 寄生组合式继承 计生组合式继承是引用类型最理想的继承 阅读全文
posted @ 2018-04-19 11:19 sunmarvell 阅读(205) 评论(0) 推荐(0) 编辑
摘要: 原型式继承 基于已有的对象创建新对象 ①obj()浅复制 对象的属性会共享 function obj(o){ function F(){} F.prototype=o; return new F(); } var person={ name:"zhangsan", age:18, friends:[ 阅读全文
posted @ 2018-04-19 10:46 sunmarvell 阅读(226) 评论(0) 推荐(0) 编辑