首页 > 编程语言 > 详细

JavaScript对象

时间:2016-03-29 10:16:58      阅读:220      评论:0      收藏:0      [点我收藏+]

 

 对象属性

  constructor 属性返回对创建此对象的数组函数的引用;

  constructor(构造函数) 在对象创建或实例化时候被调用的方法.通常使用该方法来初始化数据成员和所需资源。构造函数不能被继承;

构造函数是一种特殊的方法,主要用来在创建对象时初始化对象,即为对象成员变量赋初始值.总与new运算符一起使用在创建对象语句中,特别的一个类可以有多个构造函数,可根据其参数个数的不同或参数类型的不同来区分它们,即构造函数的重载;

<scirpt>

var test = new Array();

if (test.constructor == Array){

    document.write(‘This is an Array‘);      //test为数组返回当前

}

if (test.constructor == Boolean){

    document.write(‘This is an Boolean‘);     //test为布尔值则返回当前

}

if (test.constructor == Date){

    document.write(‘This is an Date‘);        //test为Data时间则返回当前
  
}

if (test.constructor == String){

    document.write(‘This is an String‘);     //test为字符串则返回当前

}

</script>

 

 

 在JavaScript中每个函数都有名为‘prototype‘的属性,用于引用原型对象.此原型对象又有名为‘constructor‘的属性它反过来引用函数的本身这是一种循环使用

 

 

 function Animal(){} 

 function Person(){} 


 Person.prototype = new Animal(); 
 var person = new Person(); 


 alert(person.constructor);                               //Animal 

  

JavaScript对象

原文:http://www.cnblogs.com/liang1/p/5303425.html

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