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

Javascript中的一些坑儿~ #54

Open
shinena opened this issue May 14, 2019 · 1 comment
Open

Javascript中的一些坑儿~ #54

shinena opened this issue May 14, 2019 · 1 comment

Comments

@shinena
Copy link
Owner

shinena commented May 14, 2019

我们经常会使用到 javascript:void(0) 这样的代码,那么在 JavaScript 中 javascript:void(0) 代表的是什么意思呢?

javascript:void(0) 中最关键的是 void 关键字, void 是 JavaScript 中非常重要的关键字,该操作符指定要计算一个表达式但是不返回值。

@shinena
Copy link
Owner Author

shinena commented May 14, 2019

对于 CommonJS 和 ES6 中的模块化的两者区别是:

前者支持动态导入,也就是 require(${path}/xx.js),后者目前不支持,但是已有提案

前者是同步导入,因为用于服务端,文件都在本地,同步导入即使卡住主线程影响也不大。而后者是异步导入,因为用于浏览器,需要下载文件,如果也采用同步导入会对渲染有很大影响

前者在导出时都是值拷贝,就算导出的值变了,导入的值也不会改变,所以如果想更新值,必须重新导入一次。但是后者采用实时绑定的方式,导入导出的值都指向同一个内存地址,所以导入值会跟随导出值变化

后者会编译成 require/exports 来执行的

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

1 participant