Drkcore

13 02 2012 coffeescript Tweet

CoffeeScriptで自分のメソッドを呼び出す

exports.Test = class Test
  method_a: () -> method_b()
  method_b: () -> console.log("method b")

がmethod_bが見つからないっていうエラーが出た。

coffee> Test = require("./test").Test
[Function: Test]
coffee> t = new Test
{}
coffee> t.method_a()
ReferenceError: method_b is not defined

小一時間悩んだ挙句@が必要なことに気づいた

exports.Test = class Test
  method_a: () -> @method_b()
  method_b: () -> console.log("method b")

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021