繁体   English   中英

无法在节点 JS 中从另一个箭头 function 调用箭头 function

[英]Can't call arrow function from another arrow function in Node JS

考虑代码:

module.exports = class SuperGenerator {
    Generate = packageId => {

        // ... 
        TestMe();

    }


    TestMe = () => {
        console.log("Test Me...");
    };  

}

当我运行代码时,没有调用TestMe

为什么?

如果是简单的TestMe() ,则需要调用this.TestMe() )

所以有几件事。 如果您谈论的是 class 函数,那么您需要使用this调用它们(例如this.TestMe() )但是如果您谈论的是两个函数表达式,它们不会被提升,因此您必须在需要之前定义它们使用它们。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM