inheritConstructorStealing.js
2015-11-10 17:31
465 查看
// 借用构造函数 // 其基本思路是在子类型构造函数的内部调用父类型的构造函数 function Person(name){ this.name = name; this.friends = ["Jack","John","Kim"]; } function SuperPerson(name,sex){ //继承Person Person.call(this,name);//call()将Person的运行作用域绑定到了SuperPerson上 //如果要屏蔽父类型中的属性,要在继承语句之后添加 //实例属性 this.sex = sex; } var Tom = new SuperPerson("Tom","man"); Tom.friends.push("Amy"); console.log(Tom.friends);// ["Jack", "John", "Kim", "Amy"] var David = new SuperPerson("David","man"); console.log(David.friends);//["Jack", "John", "Kim"] console.log(David.name);//David
相关文章推荐
- inheritCombinedParasitic.js
- inheritCombination.js
- ImmediateFunc.js
- domOperation.js
- callback.js
- array.js
- asynchronous.js
- addEventListener.js
- 浅谈使用MVC模式进行JavaScript程序开发
- JavaScript 各种遍历方式详解
- js 回到顶部(兼容ie)
- javascript小知识
- js中dom的document对象
- 使用JSP页面生成PDF报表
- JS 实现瀑布流
- 每天一篇javascript学习小结(基础知识)
- JS基础知识点整理
- javascript实用技巧小知识
- JavaScript权威指南读书笔记
- JS——方法