破坏它的是分号删除。
即使你改变它也会起作用......
var asd;
简单到这个……
;
原因是下一行代码以 开头(
,恰好是用它的结尾包装了一个函数)
。
这被解释为函数调用运算符,并试图调用前一个表达式。
MyApp.util.toXML = function(options, obj) {
// your code
return result.join("");
}
// var asd; // removing the semicolon
// |------seen as invoking the result of the previous expression and passing
// v the function as an argument.
(function(toXML) {
// your code
})(MyApp.util.toXML);
// ^---------------^ This is then attempting to invoke the return value
// of "toXML", which if it successfully returned, returned a String, which
// can't be invoked.