//这个继承方式是给新人看的,逻辑简单一些 Object.extend=function(props){ //继承父类 var prototype=Object.create(this.prototype) //初始化函数ctor var _Class=function(){ if (this.ctor) this.ctor.apply(this, arguments); } //当前类属性和方法 for(var k in props){ prototype[k]= props[k] } _Class.prototype = prototype; //类继承 _Class.extend=this.extend; //类扩展 _Class.expand = function (prop) { for (var name in prop) { prototype[name] = prop[name]; } }; return _Class } //demo var Node=Object.extend({ name:"caoke1", ctor:function(name){ this.name=name } }) var Node2=Node.extend({ name:"caoke1", ctor:function(name){ this.name=name } }) cc=console var n=new Node("caoke2") var n2=new Node2("caoke3") cc.dir(n) cc.log(n2)