繁体   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