Using jQuery as suggested by Wordpress内访问的功能,我已经包裹着我在一个匿名函数的代码,这样的jQuery不会与其他JavaScript库冲突:的Javascript:匿名函数
(function($) {
// Inside of this function, $() will work as an alias for jQuery()
// and other libraries also using $ will not be accessible under this shortcut
})(jQuery);
的问题是,我想我的代码分割成两个文件:1)main.js和2)utility.js。
当两者都被封装时,主程序(main.js)如何在其他文件(utility.js)中调用函数?
utility.js
(function($) {
function doSomething() {
/* code here */
}
})(jQuery);
main.js
(function($) {
$(document).ready(function(){
doSomething();
}
})(jQuery);
感谢
除了下面的答案,我会看看[namespacing](http://addyosmani.com/blog/essential-js-namespacing/) – Tomanow
感谢您阅读Tomanow。将研究这一点。 – alds