Although I think the documentation would be better served by first showing the code. Its very short and very self explanatory. It's double awesome that it hooks into Functional Javascript.
I think he should use simpler and more direct examples. I mean, Go only make the example more complicated with the intersection and stuff. It's like if I'm trying to show how filter works by using a 20 lines example of a game.. why not use a simple <p> and show what you can do with it in a simple one liner?
Ok, I know why, since it's functional stuff and more than that, COMBINATOR STUFF, it needs to be more complicated than what it should be.
Or it could be that those are examples from his own code and he simply copied and pasted them without thinking that they might not be as useful as contriving more simple examples.
Actually, yes. At the end of his "tutorial", he explains in more succinct words what those functions do, and he use simpler examples. I suggest that instead of hiding them somewhere at the end in the middle of a paragraph, he put them in emphasis at the begin of the document.
I was playing a bit with this code last night and made a slight variation for some code I was writing, which I find easier to use
//K variation
jQuery.fn.run = function(fn) {
var args = [].slice.call(arguments)
args[0] = this
fn.apply(this, args)
return this
}
//contrived example
var add = function(el, a, b) {console.log(a + b)}
//no need to curry
$(".foo").run(add, 12, 34).addClass("bar")
I avoid passing a function and its arguments in the same list but it's purely a personal preference and adding the code doesn't remove any existing functionality, so it's in.
Yeah, looking in retrospect, binding the this keyword to the function already exposes the jQuery object inside the function, so the first argument in my version was redundant.
Although I think the documentation would be better served by first showing the code. Its very short and very self explanatory. It's double awesome that it hooks into Functional Javascript.
Here is the code: