I must be a simple man, ‘cuz things like this in Javascript make me slap my sides, and go Hot damn!
function Context(base) {
if (base) {
var c = function(base) {
this.base = base;
}
c.prototype = base;
return new c(base);
}
return new function() {
// standard context functions
this.get = function() {};
// ...
}
}
// then
var a = Context();
// do things with "a"
var b = Context(a);
// "b" inherits "a" as context:
// * changes to "a" make it to "b"
// * changes to "b" don't make it to "a"
var c = Context(b);
// you get the picture ...
I don’t know what’s more exciting here, the “no-much-to-it-ness” or the “bang-for-buck-ness”, but every time I get to work with Javascript, I am excited about the actual process of crafting code.