0
구현을 here에서 typescript 으로 이식하려는 중입니다.이 방법을 사용할 수는 있지만에있는 다른 사람들과 함께 일반 fn으로 만들고 싶습니다._.indexOf의 일반 구현
var indexOfValue = _.indexOf;
// using .mixin allows both wrapped and unwrapped calls:
// _(array).indexOf(...) and _.indexOf(array, ...)
_.mixin({
// return the index of the first array element passing a test
indexOf: (array:_.List<any>, test:Function):any => {
// delegate to standard indexOf if the test isn't a function
if (!_.isFunction(test)) return indexOfValue(array, test);
// otherwise, look for the index
for (var x = 0; x < array.length; x++) {
if (test(array[x])) return x;
}
// not found, return fail value
return -1;
}
});