Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

对暴露给全局window引发的疑惑! #1038

Closed
hilonliao opened this issue Dec 3, 2013 · 4 comments
Closed

对暴露给全局window引发的疑惑! #1038

hilonliao opened this issue Dec 3, 2013 · 4 comments

Comments

@hilonliao
Copy link

define(function(require, exports, module) {
//jquery源码
module.exports = $.noConflict(true);
//module.exports = $ = jQuery = window.$ = window.jQuery;
});

如果我用下面的方式,只需要require一次jquery就可以在任何地方调用了,甚至都不用暴露给sea(module.export = $),也不需要在require(”jquery“)再进行赋值。

那假设我所以的模块只需要按规范定义成对象,最后暴露给window,或者也暴露给sea。那只需要require一次所有模块就可以在任何地方调用任何模块了,那sea的好处到底在哪儿呢?异步加载?安全?or性能优化、内存占用少?...这些优势又是怎么体现的呢?

js新手,seajs也只学了几天,表示又迷糊了,求大伙 醍醐灌顶啊~ 或者告诉我大概思路、原理什么的,拜谢!

@hilonliao
Copy link
Author

要是项目特别大,模块特别多,当然一次性require显然不合理。
我想知道这个require过的模块是存在哪里了,或者何时释放,正常CMD模块的生命周期是怎么样的? 有这方面的文档吗?

@afc163
Copy link
Member

afc163 commented Dec 3, 2013

不建议暴露到 window,全局变量的确方便,但是也是坑。尽量遵守 CommonJS 的规范来写就好了。

价值什么的这篇文章写得很好了:#547

或者这个也行:http://cyj.me/why-seajs/zh/

@afc163
Copy link
Member

afc163 commented Dec 3, 2013

第二个问题看看源码就理解了,也有很多对源码的解析文章,比如 https://github.com/island205/HelloSea.js

@hilonliao
Copy link
Author

好的,谢谢哈,我有时间再深入研究下源码~ 主要是苦逼公司逼得紧,觉得sea很好,但是还是不能完全把握,有些忧虑,那暂时按标准来做。谢谢!@afc163

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants