LoginSignup
0

More than 5 years have passed since last update.

underscoreコードリーディング(constant)

Posted at

underscoreに詳しくないので、勉強半分でソースコードを読む。

利用するバージョン

underscore.js(v1.8.3)

constantとは

underscorejs.orgのconstant

こんな説明。

_.constant(value)

Creates a function that returns the same value that is used as the argument of _.constant.

var stooge = {name: 'moe'};
stooge === _.constant(stooge)();
=> true

_.constantのargumentに使われているvalueとおなじ値を返す関数を作成します。

underscore.constant

コード的にはこのあたり。

  // Predicate-generating functions. Often useful outside of Underscore.
  _.constant = function(value) {
    return function() {
      return value;
    };
  };

valueを返す関数を返り値として返す

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