一种javascript链式多重继承的方式(__proto__原型链)

var a=function(){this.foo='bar';}
a.prototype={b:1};
var aa=function(){}
aa.prototype={c:2,__proto__:a.prototype};
var aaa=function(){}
aaa.prototype={c:3,d:4,__proto__:aa.prototype};

console.log(new a());
console.log(new aa());
console.log(new aaa());

 

可以发现,new aaa()产生的对象继承了aa类和a类的所有属性。

由于IE的__proto__不可控制,所以仅火狐和chrome支持。

posted on 2015-12-06 11:12  东篱南山  阅读(236)  评论(0编辑  收藏  举报

导航