首页 > 代码库 > js 定义类对象
js 定义类对象
//定义类
//方式一
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();
//方式一
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();
js 定义类对象
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。