gpt4 book ai didi

javascript - 为什么有些人定义javascript对象的prototype属性值

转载 作者:数据小太阳 更新时间:2023-10-29 05:52:23 26 4
gpt4 key购买 nike

<分区>

我见过很多人采用以下编码方式,但由于我通常不这样做,而且没有它我也能正常工作,我只是好奇它是否重要。注意:我将我正在谈论的行标记为//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;
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com