augmentation
add more methods to a function according to a variable value. Keep in a separate file too
by David McClelland
JavaScript
// file 1 original module
var CAVESOFCLARITY = function() {
var treasureChests = 3;
var bats = 345;
return {
stalactites: 4235,
stalagmites: 3924,
SECRET: {
openChest: function() {
treasureChests--;
alert('DA DADADA DAAAAAAA!');
}
}
};
}();
//file 2 augmentation adds to module
// file 2 lexical scope means not access to private vars in file 1
// file 1 can't access private vars in file 2 either.
CAVESOFCLARITY = function(caves){
var sandScript = '';
setSandScript : function(message){
sandScript = message;
};
}(CAVESOFCLARITY);