Skip to content

Instantly share code, notes, and snippets.

Created September 9, 2015 10:58
Show Gist options
  • Save anonymous/462f81b866910b4f51e8 to your computer and use it in GitHub Desktop.
Save anonymous/462f81b866910b4f51e8 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Sep 9, 2015.
    64 changes: 64 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    <!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>
    25 changes: 25 additions & 0 deletions jsbin.halesi.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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);