zoukankan      html  css  js  c++  java
  • javascript class 定义

    Method 1:

    var TestClass=function(){


        
    this.fun1=function(){return "我是中国人";};
        
    this.field1="这是字段";
        
    this.i1=10;
        
    this.i2=20;
        
    this.sum=function(){return this.i1+this.i2; };


    };

    var tc=new TestClass();
    alert(tc.fun1() );
    alert(tc.field1 );


    Method 
    2:  

      
    //创建连接一个字符串父类
        function StringBuffer()
        {
            
    //私有属性 _strings
            this._strings= new Array;
        }
        
    //以下为StringBuffer类2个方法
        StringBuffer.prototype.append = function (str)
        {
            
    this._strings.push(str);
        }
        StringBuffer.prototype.toString 
    = function(){
            
    return  this._strings.join('');
        }



    <script type="text/javascript">
    var TestClass=function(){
        
    this.fun1=function(){return "我是中国人";};
        
    this.field1="这是字段";
        
    this.i1=10;
        
    this.i2=20;
        
    this.sum=function(){return this.i1+this.i2; };
    };
    TestClass.prototype.toString
    =function(){
        
    return "I1:"+this.i1;
    };
    var v1=new TestClass();
    v1.i1
    =1;
    var v2=new TestClass();
    v2.i1
    =3;
    var v3=new TestClass();
    v3.i1
    =2;
    function SortDemo(){
       
    var a, l;                       // 声明变量。
       //a = new Array(1,2,10,9,8,7);
       a=[];
       a.push(v1);
       a.push(v2);
       a.push(v3);
       l 
    = a.sort(cmp);                   // 排序数组。   
      alert(l );     // 返回排序的数组。  
    }
    SortDemo();
    function cmp(a,b){
        
    return -a.i1+b.i1;
        
    //return -(a-b);
        //return parseInt(a)-parseInt(b);
    }
    </script>
  • 相关阅读:
    IbatisNet 快速开发使用 之一
    C#开发和调用Web Service
    如何构建银行数据仓库
    SQLSREVER如何创建和使用动态游标
    一个sql语句,包含有几乎所有标准查询语法
    深入研究SQL结构化查询语言中的LIKE语句
    数据库正规化和设计技巧
    黑客攻破SQL服务器系统的十种方法
    实用的存储过程
    数据库人员手边系列:SQL Server常见连接错误
  • 原文地址:https://www.cnblogs.com/wucg/p/1795508.html
Copyright © 2011-2022 走看看