创建对象的方法

创建对象

var o1 =new Object();
o1.property1 ='1';
o1.property2 ='2';

工厂模式

function createObject(property1,property2){
var o =new Object();
o.property1 = property1;
o.property2 = property2;
return o;
}
var o1 = createObject('1','2');

构造函数模式

构造函数首字母大写

function O(property1,property2){
this.property1 = property1;
this.property2 = property2;
}
var o1 =new O('1','2');

原型模式

function O(){
}
O.prototype.property1 ='1';
O.prototype.property2 ='2';

var o1 =new O();
posted @ 2011-05-09 12:16  Reibin  阅读(334)  评论(0编辑  收藏  举报

日志版权保留,转载请注明来自http://www.cnblogs.com/bienfantaisie