码迷,mamicode.com
首页 > Web开发 > 详细

js 定义类对象

时间:2014-08-27 13:08:37      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:os   io   ar   cti   sp   on   new   c   type   

 //定义类
    //方式一
    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 定义类对象

标签:os   io   ar   cti   sp   on   new   c   type   

原文地址:http://blog.csdn.net/wangjuntytl/article/details/38866971

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!