对象基础:

本地对象:Object ,Array,Number,Function,String,Boolen,RegExp,Error...

(本地对象的内置方法函数)

内置对象:

宿主对象(自定义对象):

定义类或者对象的方法:(混合构造函数/原型方式最常用,动态原型方式也很广泛)

工厂方式;function createTmp(){var tmp =new Object; tmp.aa="";tmp.bb=12;tmp.cc=function(){alert(this.aa)}; return tmp;} ;createTmp; 

构造函数方式;function Car(oaa,obb,occ){this.aa=oaa;this.bb=obb;this.cc=occ;this.dd=function(){alert(this.cc)};} var oCar = new Car('a','b','c');

原型方式;function Car(){};Car.prototype.aa="";Car.prototype.bb="";Car.prototype.cc="";Car,prototype.dd=function(){alert(this.cc);};var car1 = new Car();

动态原型方式;function Car(oaa,obb,occ){this.aa=oaa;this.bb=obb;this.cc=occ;if(typeof Car._initlialized=="undefined"){Car.prototype.dd=function(){alert(this.cc)};Car._initialized=true;}}

混合构造函数/原型方式;function Car(oaa,obb,occ){this.aa=oaa;this.bb=obb;this.cc=occ;} Car.prototype.dd=function(){alert(this.cc)}; var ocar1 =new Car('1','2','3');

混合工厂方式;function Car(){var tmp=new Object;tmp.aa="";tmp.bb="";tmp.cc="";tmp.dd=function(){alert(this.cc)}; return tmp}; var ocar1 = new Car();

posted on 2011-12-29 17:41    阅读(110)  评论(0)    收藏  举报