Last active
September 20, 2016 15:09
-
-
Save gilbert/13d4593b00b4ee7cea33 to your computer and use it in GitHub Desktop.
Revisions
-
gilbert revised this gist
Sep 20, 2016 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,7 +4,7 @@ // // var add = function (x,y) { return x + y } // var add5 = add.papp(5) // add5(7) //=> 12 // Function.prototype.papp = function () { var slice = Array.prototype.slice -
gilbert revised this gist
Sep 20, 2016 . 1 changed file with 29 additions and 15 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -49,20 +49,34 @@ Function.prototype.coldPapp = function() { } Function.prototype.throttle = function (fn, waittime, threshhold, scope) { threshhold || (threshhold = 250); var last, deferTimer var go = function () { var context = scope || this var now = +new Date, args = arguments if (last && now < last + threshhold) { // hold on to it clearTimeout(deferTimer) deferTimer = setTimeout(function () { last = now fn.apply(context, args) }, threshhold) } else { last = now fn.apply(context, args) } } var goTimeout = null return function () { clearTimeout(goTimeout) goTimeout = setTimeout(go, waittime) } } -
gilbert revised this gist
May 22, 2015 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ // specific data to an event handler. // Example: // // var add = function (x,y) { return x + y } // var add5 = add.papp(5) // add5(7) //=> 11 // @@ -19,7 +19,7 @@ Function.prototype.papp = function () { // anchor click page jumps and form submits. // Example: // // var x = 0 // var increment = function () { x += 1 } // myAnchorEl.addEventListener('click', increment.chill()) // @@ -28,13 +28,13 @@ Function.prototype.chill = function() { return function(e) { e.preventDefault() return fn() } } // Both prevent default and partially apply in one go. // Example: // // var x = 0 // var increment = function (amount) { x += amount } // myAnchorEl.addEventListener('click', increment.coldPapp(17)) // @@ -45,8 +45,8 @@ Function.prototype.coldPapp = function() { return function(e) { e.preventDefault() return fn.apply(this, args.concat(slice.call(arguments, 1))) } } // Compose two functions together, -
gilbert revised this gist
May 21, 2015 . 1 changed file with 0 additions and 20 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -48,26 +48,6 @@ Function.prototype.coldPapp = function() { }; }; // Compose two functions together, // piping the result of one to the other. -
gilbert revised this gist
Mar 19, 2015 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -60,6 +60,7 @@ Function.prototype.coldPapp = function() { // function sumPlusTen () { // return sum.apply2(null, [10], arguments) // } // sumPlusTen(100,200) //=> 310 // Function.prototype.apply2 = function (context, args1, args2) { var slice = [].slice -
gilbert revised this gist
Mar 19, 2015 . 1 changed file with 19 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -48,6 +48,25 @@ Function.prototype.coldPapp = function() { }; }; // Apply the combination of two arrays of arguments. // Useful for dealing with fancy functions using the `arguments` keyword. // Example: // // function sum () { // var result = 0 // for (var i=0; i < arguments.length; i++) { result += arguments[i] } // return result // } // function sumPlusTen () { // return sum.apply2(null, [10], arguments) // } // Function.prototype.apply2 = function (context, args1, args2) { var slice = [].slice var args = slice.call(args1).concat(slice.call(args2)) return this.apply(context, args) } // Compose two functions together, // piping the result of one to the other. -
gilbert revised this gist
Mar 16, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -31,7 +31,7 @@ Function.prototype.chill = function() { }; }; // Both prevent default and partially apply in one go. // Example: // // var x = 0; -
gilbert revised this gist
Mar 16, 2015 . 1 changed file with 8 additions and 8 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,12 @@ // Partially apply arguments to a function. Useful for binding // specific data to an event handler. // Example: // // var add = function (x,y) { return x + y; } // var add5 = add.papp(5) // add5(7) //=> 11 // Function.prototype.papp = function () { var slice = Array.prototype.slice var fn = this var args = slice.call(arguments) @@ -15,7 +15,7 @@ Function.prototype.curry = function () { } } // Prevents the default action. Useful for preventing // anchor click page jumps and form submits. // Example: // @@ -31,14 +31,14 @@ Function.prototype.chill = function() { }; }; // Both prevent default and partially apply in one go // Example: // // var x = 0; // var increment = function (amount) { x += amount } // myAnchorEl.addEventListener('click', increment.coldPapp(17)) // Function.prototype.coldPapp = function() { var slice = Array.prototype.slice var fn = this var args = slice.call(arguments) -
gilbert revised this gist
Jan 7, 2015 . 1 changed file with 19 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -47,3 +47,22 @@ Function.prototype.coldCurry = function() { return fn.apply(this, args.concat(slice.call(arguments, 1))) }; }; // Compose two functions together, // piping the result of one to the other. // Example: // // var double = function (x) { return x * 2 } // var addOne = function (x) { return x + 1 } // var doublePlus = double.andThen(addOne) // doublePlus(3) //=> 7 // Function.prototype.andThen = function(f) { var g = this return function() { var slice = Array.prototype.slice var args = slice.call(arguments) return f.call(this, g.apply(this, args)) } } -
gilbert revised this gist
Nov 3, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ Function.prototype.curry = function () { var fn = this var args = slice.call(arguments) return function () { return fn.apply(this, args.concat(slice.call(arguments))) } } -
gilbert revised this gist
Nov 3, 2014 . 1 changed file with 20 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,11 @@ // Curry a function. Useful for binding specific data // to an event handler. // Example: // // var add = function (x,y) { return x + y; } // var add5 = add.curry(5) // add5(7) //=> 11 // Function.prototype.curry = function () { var slice = Array.prototype.slice var fn = this @@ -9,8 +15,14 @@ Function.prototype.curry = function () { } } // Simply prevent the default action. Useful for preventing // anchor click page jumps and form submits. // Example: // // var x = 0; // var increment = function () { x += 1 } // myAnchorEl.addEventListener('click', increment.chill()) // Function.prototype.chill = function() { var fn = this return function(e) { @@ -20,6 +32,12 @@ Function.prototype.chill = function() { }; // Both prevent default and curry in one go // Example: // // var x = 0; // var increment = function (amount) { x += amount } // myAnchorEl.addEventListener('click', increment.coldCurry(17)) // Function.prototype.coldCurry = function() { var slice = Array.prototype.slice var fn = this -
gilbert created this gist
Nov 3, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ // Curry a function. Useful for binding specific data // to an event handler. Function.prototype.curry = function () { var slice = Array.prototype.slice var fn = this var args = slice.call(arguments) return function () { fn.apply(this, args.concat(slice.call(arguments))) } } // Simply prevent the default action. Useful for binding // to anchor tag clicks and form submits. Function.prototype.chill = function() { var fn = this return function(e) { e.preventDefault() return fn() }; }; // Both prevent default and curry in one go Function.prototype.coldCurry = function() { var slice = Array.prototype.slice var fn = this var args = slice.call(arguments) return function(e) { e.preventDefault() return fn.apply(this, args.concat(slice.call(arguments, 1))) }; };