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();
posted @ 2016-03-07 13:24  phlsheji  阅读(213)  评论(0编辑  收藏  举报