js中prototype与constructor

2017-04-27  本文已影响0人  野薇薇

我们在定义函数的时候,函数定义的时候函数本身就会默认有一个prototype的属性;
而用new 运算符来生成一个对象的时候就没有prototype属性。
我们来看一个例子,来说明这个

function a(c){
    this.b = c;
    this.d =function(){
        alert(this.b);
    }
}
var obj = new a('test');
alert(typeof obj.prototype);//undefine
alert(typeof a.prototype);//object
上一篇 下一篇

猜你喜欢

热点阅读