export & importjavascript
例1:lib/math.jsjava
export function sum(x, y) { return x + y; } export var pi = 3.141593;
import * as math from "lib/math"; alert("2π = " + math.sum(math.pi, math.pi)); import {sum, pi} from "lib/math"; alert("2π = " + sum(pi, pi));
例2:lib/math.jsjquery
export default { pi: 3.141593, sum(x, y) { return x + y; } }
import math from '/lib/math'; alert("2π = " + math.sum(math.pi, math.pi));
動態的加載、異常加載code
System.import('lib/math').then(function(m) { alert("2π = " + m.sum(m.pi, m.pi)); });
// Directly manipulate module cache System.get('jquery'); System.set('jquery', Module({$: $})); // WARNING: not yet finalized