Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 1. CJS là commonJS. Chạy synchronous và sử dụng cho backend, hay sử dụng cho NodeJS
- //importing
- const doSomething = require('./doSomething.js');
- //exporting
- module.exports = function doSomething(n) {
- // do something
- }
- // 2. AMD stands for Asynchronous Module Definition. Chạy asynchronous và sử dụng cho front end.
- define(['dep1', 'dep2'], function (dep1, dep2) {
- //Define the module value by returning a value.
- return function () {};
- });
- // 3. UMD stands for Universal Module Definition. Sử dụng được cho front end và backend, và thường được gọi fallback cho ESM nếu ko run được ESM
- (function (root, factory) {
- if (typeof define === "function" && define.amd) {
- define(["jquery", "underscore"], factory);
- } else if (typeof exports === "object") {
- module.exports = factory(require("jquery"), require("underscore"));
- } else {
- root.Requester = factory(root.$, root._);
- }
- }(this, function ($, _) {
- // this is where I defined my module implementation
- var Requester = { // ... };
- return Requester;
- }));
- // 4. ESM stands for ES Modules. Chạy front end và backend. Có thể import vào trình duyệt
- import {foo, bar} from './myLib';
- ...
- export default function() {
- // your Function
- };
- export const function1() {...};
- export const function2() {...};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement