iteratee() | Underscore JS 日本語リファレンス

引数の型を判別し関数を返す内部関数cb()に引数を渡す関数。

■使用例

var arr = [ 
	{ works :  "悠久の社", author : "kokia" }, 
	{ works :  "Currents", author : "kokia,上野洋子" }, 
	{ works :  "愛の輪郭", author : "kokia" },  
	{ works :  "The Voice", author : "kokia" }, 
	{ works :  "I believe 海の底から", author : "kokia" }, 
	{ works :  "調和", author : "kokia" }
];
// re = [ "悠久の社", "Currents", "愛の輪郭", "The Voice", "I believe 海の底から", "調和" ];
var re = _.map( arr, _.iteratee("works"));
// re2 = [ [{"works":"悠久の社","author":"kokia"},{"works":"Currents","author":"kokia,上野洋子"},{"works":"愛の輪郭","author":"kokia"},{"works":"The Voice","author":"kokia"},
{"works":"I believe 海の底から","author":"kokia"},{"works":"調和","author":"kokia"}], [] ];
var re2 = _.partition( arr, _.iteratee("works"));

■内部構造

  _.iteratee = function(value, context) {

// cb関数は第1引数「value」が関数でない場合は、_.matcher(value); か _.property(value); に代入される。
    return cb(value, context, Infinity);
  };

このページのトップへ戻る
Menu