es6(十): Module的基本用法

export

// profile.js
export var firstName = 'David';
export var lastName = 'Belle';
export var year = 1973;

等价于
var firstName = 'David';
var lastName = 'Belle';
var year = 1973;
export {first, lastName, year}


import

import {firstName, lastName, year} from './profile';
import {someMethod, another as newName} from './expoter';

export default 语句

如果不想为某个属性或方法指定输入的名称,可以使用export default 语句。

export default function foo() {
    console.log('foo');
}

export default 42;


export {area as circleArea} from 'circle';

你可能感兴趣的:(es6)