Configurable
Make a function configurable
Configurable functions modify their configuration.
The configuration is available from the function context this
{ console;} bar; // 'foo value is 1'configfoo = 3;bar; // 'foo value is 3'
The configurable behavior modifies the function object, adding one method for each item in the configuration.
The added methods use the same name as the configuration items. The added methods are both setters and getters, which means that they return the config value when called without argument, and they modify the config value when called with an argument.
Additionally each config change create a new configured function. This way it is easy to have several copy of the same function with different configuration.
bar1 = ; // Now bar has a foo() methodbar1; // 1; // 'foo value is 1' var bar2 = bar1; // 'foo value is 2'bar2; // 2 // but bar1 stay the samebar1; // 1; // 'foo value is 1'
You can also configure a literal of function, this allow for several function to share the same config.
var foo = { console; } { console; } var foo1 = ;foo1; // bar value is hellofoo1; // reversed bar value is olleh var foo2 = foo1foo2; // 'bar value is bye'foo2; // 'reversed bar value is yeb'