簡體   English   中英

這個原型是否在 class function 構造函數中?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM