标签:wordpress 优化 执行 引擎 arc hello blog 输入 规格
出现时间 | 加载机制 | 输出 | 用法 | 特点 | |
---|---|---|---|---|---|
require | 2009 | 运行时加载 | 浅拷贝 | 见下 | 社区方案,提供了服务器/浏览器的模块加载方案。非语言层面的标准。只能在运行时确定模块的依赖关系及输入/输出的变量,无法进行静态优化。 |
import | 2015 | 静态编译 | 值引用 | 见下 | 语言规格层面支持模块功能。支持编译时静态分析,便于JS引入宏和类型检验。动态绑定 |
const fs = require(‘fs‘)
exports.fs = fs
module.exports = fs
import fs from ‘fs‘
import {default as fs} from ‘fs‘
import * as fs from ‘fs‘
import {readFile} from ‘fs‘
import {readFile as read} from ‘fs‘
import fs, {readFile} from ‘fs‘
export default fs
export const fs
export function readFile
export {readFile, read}
export * from ‘fs‘
模块 | 浏览器 | node |
---|---|---|
require | x | 支持 |
es module | look | node > 13 |
// ES2015 modules
// ---------------------------------
// one.js
console.log(‘running one.js‘);
import { hello } from ‘./two.js‘;
console.log(hello);
// ---------------------------------
// two.js
console.log(‘running two.js‘);
export const hello = ‘Hello from two.js‘;
// CommonJS modules
// ---------------------------------
// one.js
console.log(‘running one.js‘);
const hello = require(‘./two.js‘);
console.log(hello);
// ---------------------------------
// two.js
console.log(‘running two.js‘);
module.exports = ‘Hello from two.js‘;
es6
running two.js
running one.js
hello from two.js
commonjs
running one.js
running two.js
hello from two.js
标签:wordpress 优化 执行 引擎 arc hello blog 输入 规格
原文地址:https://www.cnblogs.com/jlzt/p/12935997.html