首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

javascript种的创建的多种方式

2012-10-10 
javascript类的创建的多种方式基本方法很简单,但在javascript中创建类有多种方式。看例子代码,主要是类方法

javascript类的创建的多种方式

基本方法很简单,但在javascript中创建类有多种方式。

看例子代码,主要是类方法的写法不一样。

1.?function people(name){
???????? ?this.name=name;
??????????this.printInfo=function(){document.write(this.name);};
??}
??

2.?

? ?var people=function(name){
???this.name=name;
???this.printInfo=function(){document.write(this.name)}
??}

?

3.

??var people=function(name){
???this.name=name;
???this.printInfo=printInfo;
??}
??
??function printInfo(){document.write(this.name)}

?

4.??var people=function(name){
???this.name=name;
??}
??
??people.prototype.printInfo=function(){document.write(this.name)}

?

5.??var people=function(name){
???this.name=name;
??}
??
??people.prototype={
???printInfo:function(){document.write(this.name)}
??}

?

?

热点排行