箭头函数的非法调用错误

时间:2017-03-08 09:50:54

标签: javascript

执行以下代码时出错:

let myFunc4 = (nameFunction) => ("Hello " + nameFunction() + ".");
let printName = (nameFunction, printFunction) => printFunction(myFunc4(nameFunction));
printName(function () { return "Adam" }, console.log);

它应该返回“Hello Adam”,但是我收到以下错误:

 Error: (SystemJS) Illegal invocation TypeError: Illegal invocation at printName

我发现很难在花费大量时间查看控制台日志后发现问题所在。

1 个答案:

答案 0 :(得分:0)

这很好。请运行摘要。您正在节点中运行吗?如果是这样,请将其更新为最新版本。

let myFunc4 = (nameFunction) => ("Hello " + nameFunction() + ".");
let printName = (nameFunction, printFunction) => printFunction(myFunc4(nameFunction));
printName(function() {
  return "Adam"
}, console.log);