js prototype 和constructor

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
       
        }

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