laughinghan/mathquill — pull request #118 by laughinghan (2012-08-23 01:02:55+00:00)
Title: Add util HOFs and magickify Node::bubble, postOrder, eachChild

@jayferd how far is too far?

these commits add `variadic()` and `send()` and use them to make `Node::bubble`, `postOrder`, and even `eachChild` accept both strings and functions (in the case of a string, call the method of that name on each node if there is one) as their first argument, and pass along all subsequent arguments to the function. Convenient in the, well, one place they're used, but very magical and indirect and probably kinda difficult to follow and basically never used, so this kinda violates YAGNI. And by kinda I mean very much. But it was so much fun! JavaScript is so powerful!

There are also performance implications of using `arguments` (in particular, the return value of `send()` is variadic and is called repeatedly in loops, and it has to be for `bubble` to remain variadic), but I don't think we ever have loops long enough to make a dent compared to DOM latency, and I think they might go away by simply having `variadic()` return a function declared like `function(_1, _2, _3) { ... }` (since we never actually call our variadic functions with more than 3 arguments. Which is really just says that we don't actually need variadic functions).