小编cg.*_*ike的帖子

为什么有些人定义了javascript对象的原型属性值

我已经看到人们做了很多次编码的方式,但是我通常不这样做,没有它我就可以正常工作,我只是好奇它是否重要. 注意:我标记了我所说的线条// this line

function Test(name, something){
    this.name = name;
    this.something = something
}
Test.prototype.name = ''; // this line
Test.prototype.something = ''; // this line

Test.prototype.getName = function(){
    return this.name;
}
Run Code Online (Sandbox Code Playgroud)

javascript

5
推荐指数
2
解决办法
106
查看次数

标签 统计

javascript ×1