Skip to content

Instantly share code, notes, and snippets.

@cheng470
Last active August 29, 2015 14:12
Show Gist options
  • Save cheng470/5a5ad922e2f359a8e2f3 to your computer and use it in GitHub Desktop.
Save cheng470/5a5ad922e2f359a8e2f3 to your computer and use it in GitHub Desktop.
反对使用IIFE的其中一个理由是可读性差,如果你有大量的JavaScript代码都在一段IIFE里,要是想查找IIFE传递的实际参数值,必须要滚动到代码最后。幸运的是,你可以使用一个更可读的模式:
+function () {
};
(function () {
});
void function() {
};
(function (library) {
// Calls the second IIFE and locally passes in the global jQuery, window, and document objects
library(window, document, window.jQuery);
}
// Locally scoped parameters
(function (window, document, $) {
// Library code goes here
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment