_ _
| | | |
_ __ ___| |__ | | __ _ _______
| '__/ _ \ '_ \| |/ _` |_ / _ \
| | | __/ |_) | | (_| |/ / __/
|_| \___|_.__/|_|\__,_/___\___|
A crazy way of template-izing your JS Function
s and Generator
s so they can
be generated on the fly.
This should be used for methods that are instantiated once then used many times, since currently the function generation does take quite a bit of time to do.
API
reblaze(values[, name], fn)
values
{Object}name
{String} Default''
fn
{Function}- Returns new Function
Examples
Let's show a simple example then allow you to go experiment.
'use strict'; const reblaze = ; { this_rows = rows >>> 0; this_cols = cols >>> 0; // Replace template entries with fields in passed object. thissumCols = ; this_data = this_rows * this_cols;} // This will look funky due to the template convention. { const data = this_data; // Sum of values may exceed a uint32 const sum = COLS; for var i = 0; i < COLS * ROWS; i++ sumi % COLS += datai; return sum;} // Build a new Matrix instance with custom sumCols().const m = 11 7;
Now sumCols
on the instance m
:
{ const data = this_data; const sum = 7; for var i = 0; i < 7 * 11; i++ sumi % 7 += thisi; return sum;}
It will also automatically take care of object properties as well. For example:
{ return fooBAR;} const fn = ;
And the output for the new fn
instance:
{ return foobar;}
The name of the function can also be replaced by passing a second optional argument.
{ return fooBAR;} const fn = ;
Will generate the following function:
{ return foobar;}
If you want to have the full require
, __filename
, etc. in your function
pass module
as an optional third (or second if name
isn't provided)
argument.
{ ;};
So, give it a whirl and report any bugs. In the future I plan on implementing
even more meta-ness where reblaze
can run on itself and return optimized
instances for a given construction case.