-
-
Save scarfunk/6b4434cbbf75733bd6c9 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/halesi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function chained(functions) { | |
function apply(param){ | |
// (3) param 3 이 넘어왔다. | |
result = param; | |
// (4) 배열의 끝부터. f2. | |
// (6) 반복. f2(3); | |
for(f of functions.reverse()){ | |
// (5) result는 f2(3); | |
result = f(result); | |
} | |
// (7) 최종으로 다실행되고 result 반환. | |
return result; | |
} | |
// (1) 함수 객체를 넘긴다. | |
// (2) apply(3) 이 실행 | |
return apply; | |
}; | |
function f1(x){ return x*2; }; | |
function f2(x){ return x+2; }; | |
// expect (3+2)*2 => 10; | |
var x = chained([f1,f2])(3); | |
console.log(x); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function chained(functions) { | |
function apply(param){ | |
// (3) param 3 이 넘어왔다. | |
result = param; | |
// (4) 배열의 끝부터. f2. | |
// (6) 반복. f2(3); | |
for(f of functions.reverse()){ | |
// (5) result는 f2(3); | |
result = f(result); | |
} | |
// (7) 최종으로 다실행되고 result 반환. | |
return result; | |
} | |
// (1) 함수 객체를 넘긴다. | |
// (2) apply(3) 이 실행 | |
return apply; | |
}; | |
function f1(x){ return x*2; }; | |
function f2(x){ return x+2; }; | |
// expect (3+2)*2 => 10; | |
var x = chained([f1,f2])(3); | |
console.log(x);</script></body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function chained(functions) { | |
function apply(param){ | |
// (3) param 3 이 넘어왔다. | |
result = param; | |
// (4) 배열의 끝부터. f2. | |
// (6) 반복. f2(3); | |
for(f of functions.reverse()){ | |
// (5) result는 f2(3); | |
result = f(result); | |
} | |
// (7) 최종으로 다실행되고 result 반환. | |
return result; | |
} | |
// (1) 함수 객체를 넘긴다. | |
// (2) apply(3) 이 실행 | |
return apply; | |
}; | |
function f1(x){ return x*2; }; | |
function f2(x){ return x+2; }; | |
// expect (3+2)*2 => 10; | |
var x = chained([f1,f2])(3); | |
console.log(x); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment