const x = { a:1 };
(function q({a}){
console.log(a);
return a;
})(x); // unable to execute
console.log(q(x))
我无法执行第6行。为什么?在第3行中,如果我删除第6行,控制台将正常工作:
Error: q is not defined
const x = { a:1 };
// This IIFE isn't assigned to a variable in global. No reference to the object
(function q({a}){
console.log(a);
return a;
})(x); // unable to execute
这有效,但是您不能再次调用它,因为a返回了q并且q不是函数:
const x = { a:1 };
// This IIFE isn't assigned to a variable in global. No reference to the object
const q = (function ({a}){
console.log(a);
return a;
})(x); // unable to execute
console.log(q)