1.6.Module
模組化的好處
模組
當要為相同介面產生多個實作時, 可撰寫一個預設實作作為原型, 可使用stampit(https://github.com/stampit-org/stampit)
stampit: a coposable factory
stampit.init
初始化property, 可傳入參數
example:
stampit.props
當初始化完成後指定進行後續動作,或是可以賦值給property *example:
stampit.methods
定義function
example:
stampit.compose
允許繼承任意數量的來源 (with last-in priority.)
example:
常見的模組
模組模式 (module pattern)
非同步模組定義 (AMD)
AMD模組載入器
Require.js
Curl.js
CommonJS模組規範
是一個由CommonJS group所定出的module format, 是在Node上使用的模組撰寫風格
webpack 也是遵循這個規範
匯出: export
匯入: require
Last updated
Was this helpful?