LoginSignup
0
0

More than 5 years have passed since last update.

coffeescriptのクラス/インスタンスのメソッド/変数の書き方

Last updated at Posted at 2017-08-23
hedachi直伝

class MyClass
  # クラスメソッド
  @classMethod = ()->
    # クラスメソッドを呼ぶ場合
    @classMethod2()

    # クラス変数を呼ぶ場合
    @classVar

    # インスタンスメソッドは呼べない

    # インスタンス変数は呼べない


  # クラス変数
  @classVar = 1

  # インスタンスメソッド
  instanceMethod:()->
    # クラスメソッドを呼ぶ場合
    MyClass.classMethod()
    @constructor.classMethod()

    # クラス変数を呼ぶ
    MyClass.classVar
    @constructor.classVar

    # インスタンスメソッドを呼ぶ場合
    @instanceMethod()

    # インスタンス変数を呼ぶ場合
    @instanceVar

  # インスタンス変数
  constructor:->
    @instanceVar = 1

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0