に、私は無名関数で@
キーワードのスコープを持ついくつかの問題CoffeeScriptの範囲クラス
(これは何が起こっているかではなく、私は私の例のためにそれを必要とする)
3210 を持っていますこれは、例えばwindow
にクラス
class Example
stuff: []
otherStuff: createArray ->
@stuff
@
点(私は推測)です。そこで私はこれを調べ、fat arrowを思い出してジェネレータ関数を作成しました。
私はこの
class Example
stuff: []
otherStuff: createArray =>
@stuff
を試みたが、それもfunction(_this) { ...}(this)
にコンパイルされませんでした。だから、私はすべての発電機でラップしようとし始めた
class Example
stuff: []
otherStuff: =>
createArray ->
@stuff
...
otherStuff: =>
stuff = @stuff
createArray ->
stuff
...
otherStuff: ((stuff) ->
createArray ->
stuff
)(@stuff) #this is the one that upsets me the most because it compiles to Example.stuff and not to Example.prototype.stuff
しかし、これらのどれも動作していません。
class
の代わりに単純なfunction
に切り替える前に、私が欲しいものを達成する方法はありますか?
は、私はクラスの作成時に '@ otherStuff'にバインド' createArray'の結果をしたい、それは私が自己実行中の関数を作成しようとしていた理由です。 – fra9001
さて、クラスの作成時に、まだ「これ」はありません。だから...いくらか不可能です。 – deceze