开发插件,通常是定义一个类,在javascript中就是定义一个构造函数。目前最流行的办法是采用组合寄生式构造函数,举个例子:
functionfake(obj,name){ //定义象私属性 this.target=obj; this.name=name; this.sayName=function(){ alert(this.name); }; //采用原型检测建立共属性 if(!fake.prototype.setName){ fake.prototype.type="FakeObject"; fake.prototype.setName=function(newName){ this.name=newName; }; } } varnewFakeObj=newfake("test","TommyFok");