以下の内容はhttps://tbpgr.hatenablog.com/entry/20130703/1372859254より取得しました。


Coffee Script | thisの束縛

概要

thisの束縛

詳細

以下の記法で関数定義thisの束縛して、関数の外部のthisを関数内部に
引き継ぐことができます。

instance_name = =>
  // concrete logic

Coffee Script

class Hoge
  name: "hoge"
  test: ->
    sub_hoge = =>
       console.log "#{@name}"
    sub_hoge()

new Hoge().test()

JavaScript

<script language="javascript">
var Hoge;

Hoge = (function() {
  function Hoge() {}

  Hoge.prototype.name = "hoge";

  Hoge.prototype.test = function() {
    var sub_hoge,
      _this = this;
    sub_hoge = function() {
      return console.log("" + _this.name);
    };
    return sub_hoge();
  };

  return Hoge;

})();

new Hoge().test();
</script>

出力

hoge



以上の内容はhttps://tbpgr.hatenablog.com/entry/20130703/1372859254より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14