• 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();
  • 相关阅读:
    4、2 核心组件
    promise
    Content-Type
    $routeProvider
    广告
    $apply() $digest()
    异常
    switch
    autoprefixer
    $resource
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5250171.html
Copyright © 2020-2023  润新知