0
メソッドチェーン間で別のメソッドを呼び出す方法は?オブジェクト/配列に別のメソッドを適用する
function double(base) {
return base * 2;
}
function mapDouble(target) {
return target.map(double);
}
var foo = [1,2,3].map(double);
console.log(foo); // => [2, 4, 6]
var bar = mapDouble([1,2,3]);
console.log(bar); // => [2, 4, 6]
var qux = [1,2,3].this.call(mapDouble);
console.log(qux);
// => Error {
// "message": "Uncaught TypeError: Cannot read property 'call' of undefined",
// "filename": "http://stacksnippets.net/js",
// "lineno": 24,
// "colno": 23
// }
私の実際のコードは、(私が書きたい)あなたは例えばのような任意の関数チェーンを作成するには、 "モナド" の施設を作ることができます
[1,2,3].map((value) => {
return foo;
}).filter((value) => {
return bar;
}).this.call(mapDouble);
ここでfooとbarの値を取得できますか? –