JQuery文件的开头代码:
!function(d, c) {
"object" == typeof module && "object" == typeof module.exports ? module.exports = d.document ? c(d, !0) : function(b) {
if (!b.document) {
throw new Error("jQuery requires a window with a document")
}
return c(b)
} : c(d)
}("undefined" != typeof window ? window : this, function(a, b) {
。。。。。。。
});
以上一段代码是自执行代码结构,等价于:
function AAAA(a, b) {
"object" == typeof module && "object" == typeof module.exports ? module.exports = a.document ? b(a, !0) : function(a) {
if (!a.document) throw new Error("jQuery requires a window with a document");
return b(a)
}: b(a)
}
function BBB(a, b) {
。。。
}
var paramA="undefined" != typeof window ? window: this;
AAAA(paramA,BBB);
本文解析了JQuery源码中的自执行匿名函数结构,详细介绍了其工作原理及如何处理不同环境下的模块导出。
&spm=1001.2101.3001.5002&articleId=74016985&d=1&t=3&u=487dac50529a4607b4e691ebe26df697)
463

被折叠的 条评论
为什么被折叠?



