Partial function evaluator
ABANDONEDTurns out that if you just hammer on v8's bind() enough times it gives basically the same performance as manually inlining anyway :P So there is no point to using this library (ie the concept is flawed)
var specialize = require"specialize"//Create a test functionifpredareturn a + 10return a - 10//Specializevar specialized = specializetestFunc return x > 0//Prints out 11console.logspecialized1//Prints out -11console.logspecialized-1
func by binding static values from arguments to the scope of function.
funcis the function to bind
arg1, arg2, ...are the arguments for the function to specialize. Pass in
to skip specialization.
Returns A specialized version of
Because objects have properties that can change over time this code doesn't support inlining objects. If you do pass an object it gets bound dynamically, just like calling bind() and so there isn't much benefit to this library. It is also possible to inline functions which use variables from their outside scope. An exception is made for variables in the global namespace even though this is not technically correct (since they could be rebound in a shadowing closure). This is a conscientious choice, and if you want to overload globals then you should just use bind().
What it can do is inline constant values and some closures for well encapsulated functions, giving a substantial speed up with little loss of flexibility.
After experimenting a bit, I discovered that at least in v8 there is really no point to doing all this since the native implementation of bind already does partial evaulation for you. So there is really no need for this library :P.
(c) 2013 Mikola Lysenko. MIT License