【发布时间】:2019-04-03 13:34:45
【问题描述】:
我有以下问题:我想从函数testHello调用函数printHello。 printHello 函数独立工作,但是,当我尝试从 testHello 函数调用 printHello 时,我得到一个引用错误。感谢您的帮助。
class Test {
constructor(name) {
this.name;
}
printHello(parameter) {
console.log(parameter);
}
testHello() {
printHello(printHello(this.name));
}
}
var test = new Test("Sandro");
test.printHello("hello"); //works, prints "Hello" to the Console
test.testHello(); // does not work: Reference Error: printHello is not defined
【问题讨论】:
-
this.printHello() -
在
printHello中调用printHello会得到undefined,如果你不在构造函数中初始化名字也是一样的 -
一个关于课程如何运作的简单网络搜索会自己回答这个问题
标签: javascript function referenceerror