写做背景javascript
最近在抓基础,毕竟没有好地基盖楼容易塌啊...再回首javascript,原型能够说是该语言较为核心的设计之一,咱们有必要了解下其设计理念 (#^.^#)java
基本概念chrome
原型对象图解
说明浏览器
Object、Function和原型关系函数
说明this
原型链实现继承
本图参考实现代码见javascript高级程序设计spa
function SuperType(){ this.property = true; } SuperType.prototype.getSuperValue = function(){ return this.property; }; function SubType(){ this.subproperty = false; } //继承了SuperType
SubType.prototype = new SuperType(); SubType.prototype.getSubValue = function (){ return this.subproperty; }; var instance = new SubType(); alert(instance.getSuperValue()); //true
原型链弊端firefox
但愿文章对小伙伴有所帮助,也很是欢迎指出文章存在问题,emmmmmmmmmm......prototype