zoukankan      html  css  js  c++  java
  • Array对象的三种属性实例

     

    length 属性

    定义和用法

    length 属性可设置或返回数组中元素的数目。这个很常见了

    语法

    arrayObject.length

    prototype 属性

    定义和用法

    prototype 属性使您有能力向对象添加属性和方法。

    语法

    object.prototype.name=value

    实例

    在本例中,我们将展示如何使用 prototype 属性来向对象添加属性:

      

     1  <script type="text/javascript">
     2     //构造函数
     3   function employee(name,job,born)
     4   {
     5   this.name=name;
     6   this.job=job;
     7   this.born=born;
     8   }
     9   //new一个新的实例,bill,他继承了了employee的所有属性
    10  var bill=new employee("Bill Gates","Engineer",1985);
    11  //向employee原型上添加salary属性
    12  employee.prototype.salary=null;
    13   //这个属性可以被bill继承到
    14  bill.salary=20000;
    15  
    16  document.write(bill.salary);
    17  
    18  </script>

    输出:

    20000

    constructor属性
    constructor 属性返回对创建此对象的数组函数的引用。
    <script type="text/javascript">
    //构造函数
    function employee(name,job,born)
    {
    this.name=name;
    this.job=job;
    this.born=born;
    }
    
    var bill=new employee("Bill Gates","Engineer",1985);
    
    document.write(bill.constructor);
    
    </script>

    输出:

    1 function employee(name, jobtitle, born)
    2 {this.name = name; this.jobtitle = job; this.born = born;}

     从结果看来,就是返回创建它的构造函数

  • 相关阅读:
    Delphi IDE 设置
    我最喜欢的歌曲
    Window 常用文件
    Delphi TTable 组件
    Delphi TDatabase 组件
    c语言->和 .
    Shell 工具之 gawk
    Shell 工具之 sed
    Shell 语法之函数
    Shell 语法之信号与作业
  • 原文地址:https://www.cnblogs.com/nostic/p/5406377.html
Copyright © 2011-2022 走看看