js 定义类对象

it2025-06-07  20

//定义类     //方式一     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();

转载于:https://www.cnblogs.com/bhlsheji/p/5250171.html

相关资源:JS中自定义类和对象
最新回复(0)