“method” method in Crockford's book: [removed] The Good Parts

前端 未结 5 1641
不知归路
不知归路 2020-12-04 17:13

Douglas Crockford wrote in his book (Page 4):

Throughout the book, a method method is used to define new methods, This is its definition:



        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 17:21

    Example: Currying can be rewritten as follows, if anyone got stuck. See jsFiddle demo

     Function.prototype.curry = function ( ) {
     var slice = Array.prototype.slice;
     var args = slice.apply(arguments);
     var that = this; 
     return function () {  
        return that.apply(null,args.concat (slice.apply(arguments)));
     }
    };
    var add = function(a, b)
    {
        return a + b;
    }
    var add1 = add.curry(1);
    document.writeln(add1(6)); // 7
    

提交回复
热议问题