varClass=function(){varklass=function(){};klass.prototype.init=function(){};//定义prototype的别名klass.fn=klass.prototype;//定义类的别名klass.fn.parent=klass;//给类添加属性klass.extend=function(obj){varextended=obj.extended;for(variinobj){klass[i]=obj[i];}if(extended)extended(klass)};//给实例添加属性klass.include=function(obj){varincluded=obj.included;for(variinobj){klass.fn[i]=obj[i];}if(included)included(klass)};returnklass;};varPerson=newClass;Person.include({save:function(id){console.log("idis:"+id);},exists:function(id){/*...*/}});varperson=newPerson;person.save();关于两个new的问题,第一个是new的是klass的实例,第二个new的是什么?打印出来的Person的原型是klass,person也是klass?这是什么情况?还是我完全理解错了?
汪汪一只猫
守候你守候我
相关分类