가져오기, 내보내기
// getType.js
// 기본 통로로 빠져나가기 때문에 함수명이 없어도 된다
// 한개의 데이터만 내보낼 수 있다
export default function (data) {
return Object.prototype.toString.call(data).slice(8, -1)
}
// getRandom.js
// 이름이 필요한 통로를 지정
// 이름만 지정되어 있으면 몇개를 내보내도 상관이 없다
export function random () {
return Math.floor(Math.random() * 10)
}
export const user = {
name: 'Yoo',
age: 35
}
// main.js
import _ from 'lodash' // From `node_modules`!
import getType from './getType' // getType.js
// 이름이 지정된 통로 데이터는 {} 로 묶어준다
import { random, user } from './getRandom' // getRandom.js
// { random, user }를 한번에 불러오려면
// import * as (사용할 이름) './getRandom' 형태
// Array
console.log(getType([1,2,3]))
// 랜덤 숫자 생성
console.log(random())
// {name: "Yoo", age: 35}
console.log(user)