javascript - How does this js snippet work? -


function thunkify(fn) {     var args = [].slice.call( arguments, 1 );     return function(cb) {         args.push( cb );         return fn.apply( null, args );     }; } 

so [] returns array object. slice.call creates new array contents of arguments starting 1 if i'm right.

but how function(cb) work? cb?

function(cb) { ... } creates function.

cb argument passed it.

you when function called.

var thunkified = thunkify(somefunction); thunkified("the value of cb"); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -