LoginSignup
2
1

More than 5 years have passed since last update.

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

Posted at

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

利用するバージョン

underscore.js(v1.8.3)

identityとは

underscorejs.orgのidentity

こんな説明。

_.identity(value)

Returns the same value that is used as the argument. In math: f(x) = x
This function looks useless, but is used throughout Underscore as a default iteratee.

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

argumentとして利用されるvalueと同じvalueを返す。例えば数学で言うとf(x) = xの数式のよう。
この関数は使いにくそうに見えるが、Underscore全体でdefaultのiterateeとして利用される。

underscore.identity

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

  // Keep the identity function around for default iteratees.
  _.identity = function(value) {
    return value;
  };

引数のvalueを返す。

2
1
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
2
1