JAVASCRIPT
Andrew University Metropolitan College
ALSO KNOWN AS
Copyright By PowCoder代写 加微信 powcoder
ES Modules
~ ECMAScript Modules
BY EXPORTING
When something is made available to other modules or pages, it’s called an export
PARTITION YOUR JS CODE
Provides a means to group your code.
Anything not exported is private.
When you include multiple .js files into your HTML, you are not provided any scope protection.
Most declarations go into the global space
MODULES ‘DEFER’
1 MODULE ONE FILE
Declare 1 module per file. That is the per specification.
DEFAULT EXPORT NAMED EXPORTS
TYPES OF EXPORTS
NAMED EXPORTS
//using multiple export keyword
export function f() { }; export class g { … }; …
export const PI = 3.14;
//or – using single export keyword
export {f, g, PI};
NAMED EXPORTS
//there can only be 1 default in your module…
export default function renderCircle(radius, fill, options) {…}
DEFAULT EXPORT
Once you import a module, it will not be imported again.
It will be cached
MODULES CAN HAVE
DIRECT DEPENDENCIES/TRANSITIVE DEPENDENCIES
When a module requires something from another module.
DIRECTORY?
? In the same folder as the module
USED BY NODE
‘../components’
Up a directory from the module,
then use a folder called ‘components’
import React from ‘react’;
You will not use require()
STRICTNESS
No need for ‘use strict’ in your modules (it’s the default)
CONDITIONAL IMPORT You cannot…
SMALLER MODULES => PERFORMANCE GAINS
Smaller is better with any download..
Optimize your code
Strict mode – all the time with modules!
ES6 SINGLE EXPORT
When you do not want to load a module upfront, but on- demand
You can load your modules when you need to use them.
Performance improvement!
The Chrome V8 team recommends it’s use:
MODULE SPECIFIERS MUST BE FULL URL’S OR RELATIVE URL’S WITH /, ./, OR ../
YOUR HTML SCRIPT TAG
MODULES: START USING THEM TODAY
You do not need to wait.
Works everywhere. (Nobody cares about IE anymore…)
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com