js模块化的三种写法例子

require.js:

content.js

define('content.js', function(){ return 'A cat';})

index.js

require(['./content.js'], function(animal){
console.log(animal); //A cat
})

commonJS

index.js

var animal = require('./content.js')
content.js
module.exports = 'A cat'

ES6的写法

index.js

import animal from './content'

content.js

export default 'A cat'

你可能感兴趣的:(js模块化的三种写法例子)