首页 > 其他 > 详细

Array对象的三种属性实例

时间:2016-04-19 00:08:20      阅读:274      评论:0      收藏:0      [点我收藏+]

 

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;}

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

Array对象的三种属性实例

原文:http://www.cnblogs.com/nostic/p/5406377.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!