码迷,mamicode.com
首页 > Web开发 > 详细

js prototype 和constructor

时间:2016-05-17 13:29:55      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

1.function 和object 都有 constructor 和prototype

2. var a=new Animal() (animal 是function或Object) a 有 constructor  没有 prototype, a的constructor 是animal.prototype.constructor

3.实例化的function 和Object 都有 constructor   是指向  被实例化的 prototype.constructor

如 var a=new Animal();  // a.constructor===Animal.prototype.constructor  true      a 没有prototype  (function)

var o =new Object() ;//obj.constructor===Object.prototype.constructor  true    o 没有prototype    (Object)

 

4.Animal.constructor 是function(){}   Animal.prototype.constructor是本身函数

 

function Anmal(name)

{

 this.name=name;

}

Animal.constructor是

function Function() {
    [native code]
}

Animal.prototype.constructor 是

function Animal(name) {
            this.name =name
       
        }

 

js prototype 和constructor

标签:

原文地址:http://www.cnblogs.com/tiancai/p/5501066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!