您的位置:首页 > Web前端 > JavaScript

js 定义类对象

2016-03-07 13:24 537 查看
//定义类

//方式一

function A_class(arg1,arg2){

this.arg1=arg1;

this.arg2=arg2;

this.toString=function(){

alert(this.arg1+" "+this.arg2)

}

}

var a_class = new A_class("aa","bb");

a_class.toString();

//方式二

function B_class(arg1,arg2){

this.arg1=arg1;

this.arg2=arg2;

}

B_class.prototype={

constructor:B_class,

print:function(){

alert(this.arg1+" "+this.arg2);

}

}

var b_class = new B_class("11","22");

b_class.print();

//方式三

function C_class(arg1,arg2){

this.arg1=arg1;

this.arg2=arg2;

}

C_class.prototype.output=function(){

alert(this.arg1+" "+this.arg2);

}

var c_class = new C_class("@@","##");

c_class.output();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: