LoginSignup
9
9

More than 5 years have passed since last update.

【CoffeeScript】`this.hoge = hoge`を書かない

Last updated at Posted at 2015-04-16

CoffeeScriptはメソッドの仮引数に@をつけることができる.

class Animal
  constructor: (@name) ->

上記のコードはこんな感じに展開される.

var Animal;

Animal = (function() {
  function Animal(name) {
    this.name = name;  // ← この行に注目!!
  }

  return Animal;

})();

このように,仮引数名に@prefixを付与すると@name = nameを書かなくても済む(コンストラクタ以外でも同様).

CoffeeScriptで怠惰を極めよう.

9
9
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
9
9