(function ($) {
console.log($('div').html())
})(jQuery)
(function ($) {
console.log($('h1').html())
})(jQuery);
ECMAScript规范具有分号自动插入规则,但是在上面代码中,在第一个立即执行函数末尾却不会插入,因为第二个立即执行函数,会被解释为如下形式:
(function ($) {
console.log($('div').html())
})(jQuery)(function ($) {
console.log($('h1').html())
})(jQuery);
因此,我们必须在第一个立即执行函数的末尾添加分号:
(function ($) {
console.log($('div').html())
})(jQuery);
(function ($) {
console.log($('h1').html())
})(jQuery);