zoukankan      html  css  js  c++  java
  • 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();
  • 相关阅读:
    归并排序
    二分查找
    分治 递归 引用 求一个数组中的最大和最小元素
    插入排序
    Poj 2503
    SELinux 基础命令
    Zend Framework中的MVC架构
    phpfpm详解
    CentOS 6 minimal 安装
    php 5.3.3 中的phpfpm配置
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5250171.html
Copyright © 2011-2022 走看看