Created
November 19, 2018 12:15
-
-
Save skysan87/ccca4fd3ea2a0c6758723b2dca58f098 to your computer and use it in GitHub Desktop.
ES module 基礎
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let day = '日' | |
let week = '週' | |
let month = '月' | |
export {day, week, month} | |
// 変数の場合defaultは使用できない | |
export let year = '年' | |
let dayOfWeek | |
export default dayOfWeek = '曜日' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sayHello(name) { | |
console.log(`Hello, ${name}`) | |
} | |
function getPrefix() { | |
return 'hello' | |
} | |
export {sayHello, getPrefix} | |
// 1ファイルにdefaultは1つまで | |
export default function(name) { | |
console.log(`Good morning, ${name}`) | |
} | |
export function sayEvening(name) { | |
console.log(`Good evening, ${name}`) | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Human { | |
constructor(name) { | |
this.name = name | |
} | |
wonder() { | |
console.log(`${this.name}は訝しんだ`) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<script type="module" src="./main.js"></script> | |
<title>ES module</title> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Human } from './human.js' | |
import defaultHello, { sayHello, sayEvening, getPrefix } from './helloUtil.js' | |
import dayOfWeek, * as Unit from './commonUnit.js' | |
const bob = new Human('bob') | |
function wonder() { | |
let jeff = new Human('jeff') | |
jeff.wonder() | |
} | |
function today() { | |
let prefix = getPrefix() | |
console.log(`${prefix}, 今日は 2018${Unit.year} 11${Unit.month} 18${Unit.day} 日${dayOfWeek}です`) | |
} | |
sayHello(bob.name) //Hello, bob | |
sayEvening(bob.name) //Good evening, bob | |
defaultHello(bob.name) //Good morning, bob | |
wonder() //jeffは訝しんだ | |
today() //hello, 今日は 2018年 11月 18日 日曜日です |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment