美文网首页
js中prototype与constructor

js中prototype与constructor

作者: 野薇薇 | 来源:发表于2017-04-27 14:11 被阅读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

相关文章

网友评论

      本文标题:js中prototype与constructor

      本文链接:https://www.haomeiwen.com/subject/utogzttx.html