ES6模块与CommonJS模块有什么区别呢?
文章目录

ES6模块与CommonJS模块有什么区别?
1、ES6 Module和CommonJS模块的区别:
CommonJS是对模块的浅拷贝,ES6 Module是对模块的引用,即ES6 Module只存只读,不能改变其值,具体点就是指针指向不能变,类似constimport的接口是read-only(只读状态),不能修改其变量值。 即不能修改其变量的指针指向,但可以改变变量内部指针指向,可以对commonJS对重新赋值(改变指针指向),但是对ES6 Module赋值会编译报错。
2、ES6 Module和CommonJS模块的共同点:
CommonJS和ES6 Module都可以对引入的对象进行赋值,即对对象内部属性的值进行改变。
详解请移步 《ES6模块与CommonJS模块的差异》
What is the difference between ES6 modules and CommonJS modules?
1、The difference between ES6 Module and CommonJS module:
- CommonJS is a shallow copy of the module, ES6 Module is a reference to the module, that is, the ES6 Module is only stored as read-only, and its value cannot be changed. The specific point is that the pointer cannot be changed, similar to const
- The import interface is read-only (read-only state), and its variable values cannot be modified. That is, the pointer pointing to the variable cannot be modified, but the internal pointer pointing to the variable can be changed, and the commonJS pair can be re-assigned (change the pointer pointing), but the ES6 Module assignment will compile an error.
Common points of ES6 Module and CommonJS module:
- Both CommonJS and ES6 Module can assign values to imported objects, that is, change the value of the internal properties of the object.
For detailed explanation, please move to 《the difference between ES6 module and CommonJS module》
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论