Skip to content

Instantly share code, notes, and snippets.

Created September 9, 2015 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/462f81b866910b4f51e8 to your computer and use it in GitHub Desktop.
Save anonymous/462f81b866910b4f51e8 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/halesi
<!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>
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