importã¨requireã©ã¡ãã使ããâ¦ã
node.jsãããç¥ããªãã£ããã®ã§ã babelã§es2015ããã«ããã¦ãã¨importãrequireã使ãã¦ãä½ãéãã®ããï¼ã¨ãªã£ãã®ã§ã¡ã¢ã
çµè«
require
ã¯ãnode.jsãã®æ¸ãæ¹ã§ãimport
ã¯ães2015ããã使ããããã«ãªã£ãæ¸ãæ¹ã¨ãããã¨ã¿ããã§ãã
ãã£ãããªã®ã§ãæ°ãã使ããããã«ãªã£ãimport
ã®æ¸ãæ¹ã«æ
£ãã¦ã¿ãããã¨æãã¾ãã
åè
Rubyist Magazine - 2015 å¹´ã® JavaScript 㨠babel ã®è©±ï¼ã¢ã¸ã¥ã¼ã«åï¼
importã¨requireã®æ¸ãæ¹
importã®æ¸ãæ¹
import 'ã¯ã©ã¹å' from 'ãã¡ã¤ã«æå®'
ã§èªã¿è¾¼ãã§ã
export default class 'ã¯ã©ã¹å' {}
ã§è¨å®ã
//èªã¿è¾¼ã¿å´ import Klass from './Klass'; //ã¯ã©ã¹ã®èªã¿è¾¼ã¿ const klass = new Klass(); //ã¯ã©ã¹ã®å®è¡
//Klass.js export default class Klass { constructor () { this.hoge(); } hoge () { console.log("å®è¡ããã¾ãã") } }
requireã®æ¸ãæ¹
require('ãã¡ã¤ã«æå®')
ã§èªã¿è¾¼ãã§ã
module.exports = class 'ã¯ã©ã¹å' {}
ã§è¨å®ã
//èªã¿è¾¼ã¿å´ const Klass = require('./Klass');//ã¯ã©ã¹ã®èªã¿è¾¼ã¿ const klass = new Klass(); //ã¯ã©ã¹ã®å®è¡
//Klass.js module.exports = class Klass { constructor () { this.hoge(); } hoge () { console.log("å®è¡ããã¾ãã") } }