面向对象与原型

var box=new Object();
box.name='lee';
box.age=180;
box.run=function(){
return this.name+this.age+'运行中....' ;
}
alert(box.run());
var box=new Object();
box.name='xxm';
box.age=58;
box.run=function(){
return this.name+this.age+'运行中....' ;
}
alert(box.run());//多次使用,非常麻烦

//工厂模式


function creatObject(name,age){
var box=new Object();
box.name=name;
box.age=age;
box.run=function(){
return this.name+this.age+"运行中.....";
}
return box;
}
var ob1=creatObject("lee",12);
var ob2=creatObject("xxm",36);
var ob3=creatObject("dds",25);
alert(ob1.run());
alert(ob2.run());
alert(ob3.run());//一次编写.多次使用.

原文地址:https://www.cnblogs.com/qq928252089/p/5003369.html