[英]functions an immediate strange behavior error in console.log
I have code: 我有代码:
function fn(ob)
{
console.log(ob.name)
}
fn({name:"myName"})
(function(text){
console.log(text)
})("Error")
But when i run this i get TypeError: fn(...) is not a function [Learn More] on console. 但是当我运行这个时,我得到TypeError:fn(...)不是控制台上的[了解更多]功能。 Why?
为什么?
You need to separate between the call to the fn
function and the definition (and call) to the anonymous function. 您需要将对
fn
函数的调用与对匿名函数的定义(和调用)分开。
You can do this using the ;
你可以使用
;
char after the call to the fn
function: 调用
fn
函数后的char:
function fn(t) { console.log(t.name) } fn({name:"myName"}); (function(text){ console.log(text) })("Error")
Otherwise your code is actually: 否则你的代码实际上是:
fn({name:"myName"})(function(text){
console.log(text)
})("Error")
And this is the error you got. 这就是你得到的错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.