一.工厂方式:先创建对象,再向对象添加方法和属性,封闭后调用不要使用new操作符创建对象。使用这种方法有很多弊端,把方法定义在工厂函数内部的时候,每次调用的时候都会产生新的函数
function factory(name,person,address,time){
var tmp=new Object;
tmp.name=name;
tmp.person=person;
tmp.address=address;
tmp.workTime=function(){
alert("we start to work at" + time);
}
return tmp;
}
var factory1=factory("drugs",100,"huashan Rd",10);
var factory2=factory("TCMdrugs",100,"hongqiao Rd",11);
factory1.workTime();
factory2.workTime();//Here,factory1 and factory2 ha...[ 查看全文 ]