Skip to content

Instantly share code, notes, and snippets.

@agoalofalife
Last active July 6, 2017 07:15
Show Gist options
  • Save agoalofalife/a9a87abb5b4eb4da5f76dfc08c066a6b to your computer and use it in GitHub Desktop.
Save agoalofalife/a9a87abb5b4eb4da5f76dfc08c066a6b to your computer and use it in GitHub Desktop.
Способ применения каррирования в js
Function.prototype.partial = function(){
var fn = this, args = Array.prototype.slice.call(arguments)
return function(){
var arg = 0
for (var i = 0; i < args.length && arg < arguments.length; i++) {
if(args[i] === undefined) {
args[i] = arguments[arg++]
return fn.apply(this, args)
}
}
}
}
// example
var delay = setTimeout.partial(undefined, 10000)
delay(function(){
console.log('after 10 sec')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment