- テスト
5 :trydev[sage]:2014/07/13(日) 16:01:14.82 ID:F2hThxmf - module Test:
i: 0 static: main: -> alert @i
|
- CoffeeScript
322 :trydev[age]:2014/07/13(日) 16:20:30.09 ID:F2hThxmf - モジュールのテスト
インスタンス何それ、staticなロジック関数最高(?)誰得なscriptです。 使い方 module モジュール: 他のモジュール.. プライベート: 値or関数 static: パブリック: 値or関数 main: -> alert @プライベート alert @他のプライベート alert モジュール.パブリック # むむ! alert 他のモジュール.他のパブリック # むむむむ!! alert オブジェクト # [module モジュール] モジュール.main() # モジュール.static.main() 今のところMain.static.mainをエントリポイントとしていますが、 サンプルの様にMain定義前の実行は可能です。
|
- CoffeeScript
323 :trydev[age]:2014/07/13(日) 16:21:32.96 ID:F2hThxmf - # モジュール化関数
# 変数の概要 # o ・・・ object # m/n ・・ object名 # a ・・・ argument # s ・・・ staticな関数名 module = (o) -> for m of o if typeof o[m] is 'function' @[m]= o[m] else @[m]=(a) -> for n of o[m] if typeof a[n] is 'undefined' a[n] = o[m][n] a for s of o[m]['static'] @[m][s]=(a) -> o[m]['static'][s].call o[m], a @[m].toString=-> "[module #{m}] " try @Main.main.call @ if m is 'Main' catch e
|
- CoffeeScript
324 :trydev[age]:2014/07/13(日) 16:23:57.71 ID:F2hThxmf - # サンプル - Base.iをインクリメント・デクリメント・表示
module Base: i: 0 static: main: -> alert @i alert Base # [module Base] Base.main() # 0 module Inc: Base inc: ->@i++ module Dec: Base dec: ->@i-- module Show: Base show: -> alert @i # モジュールのMixinは関数の呼び出しなので # 最後のモジュールに空のオプジェクトを渡す module Program: Inc Dec Show {} module Main: Program static: main: -> @show()# 0 @inc() @show()# 1 @dec() @show()# 0
|