Last active
August 29, 2015 14:12
-
-
Save cheng470/5a5ad922e2f359a8e2f3 to your computer and use it in GitHub Desktop.
反对使用IIFE的其中一个理由是可读性差,如果你有大量的JavaScript代码都在一段IIFE里,要是想查找IIFE传递的实际参数值,必须要滚动到代码最后。幸运的是,你可以使用一个更可读的模式:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+function () { | |
}; | |
(function () { | |
}); | |
void function() { | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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