2016-12-02 4 views
-1

JSで高次関数をテストしていますが、エラーが続いています 'map is undefined'誰でも手助けできますか?マップは未定義エラー - 高次関数

function mapper(f) { 
    return function(a) { return map(a, f); }; 
} 

var increment = function(x) { return x+1; }; 
var incrementer = mapper(increment); 
incrementer([1,2,3]) 

答えて

3

mapグローバル関数ではなく、a property of Array's prototype

function mapper(f) { 
 
    return function(a) { return a.map(f); }; 
 
} 
 

 
var increment = function(x) { return x+1; }; 
 
var incrementer = mapper(increment); 
 
var out = incrementer([1,2,3]) 
 

 
console.log(out); // [2,3,4]

関連する問題