错误“TypeError: string is not a function”到底是什么意思? 哪些条件会触发错误?
一些上下文来显示错误出现的位置。
下面的程序
"use strict;"
((console["log"])(42));
报错
/private/var/folders/k6/grq8nv093hj78x5m172d725m0000gn/T/tmp14388866091438886609658.js:2
((console["log"])(42));
^
TypeError: string is not a function
at Object.<anonymous> (/private/var/folders/k6/grq8nv093hj78x5m172d725m0000gn/T/tmp14388866091438886609658.js:2:1)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
在 Node 中。但是 console["log"]
又名 console.log
应该是一个函数。
但是这个程序
"use strict;"
function displayln(v){return ((console["log"])(v));};
(displayln(42));
运行没有任何错误。
最佳答案
我认为它认为您正在尝试将“use strict;”
作为函数执行。尝试在后面添加分号
"use strict";
((console["log"])(42));
关于javascript - "TypeError: string is not a function"的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31863629/