[英]JavaScript: change a variable with a prototype function inside the constructor
[英]Are this prototype inside the class function constructor?
class Person {
constructor(name) {
this.name = name;
}
}
methodProto() {
console.log('hello pro ' + this.name);
}
}
methodProto是 Person function 構造函數的原型嗎? 如果不是,那是什么,對不起,我還在學習,所以我可能聽起來很愚蠢....
是的 - 見:
class Person { constructor(name) { this.name = name; } methodProto() { console.log('hello pro ' + this.name); } } console.log(Person.prototype.methodProto);
ES class 語法主要是語法糖。 這是為了向后兼容而存在的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.