I very much appreciate these truly edifying posts of yours...
Weedpacket;10998526 wrote:In prototypal inheritance, one object can serve as the "prototype" for another (a JavaScript object's prototype is found in it's [font=monospace]prototype[/font] property). All objects with a common prototype share that prototype object's properties (the actual properties, by reference - they don't just gain their own properties with the same names: changing the properties of a prototype (including adding or removing them) changes them for all its descendants). An object can also switch to having another prototype.
I think your one paragraph here is more informative than even the mozilla docs. They provide an example here and it looks to me like it's redundant for them to use the apply method and also set a prototype (e.g., Food.prototype = new Product()). I believe I understand what the apply function does (in that it sets properties on this from some other Object by calling a constructor in some weird way) but the reason for the prototype assignment escapes me:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function Product(name, price) {
this.name = name;
this.price = price;
if (price < 0)
throw RangeError('Cannot create product "' + name + '" with a negative price');
return this;
}
function Food(name, price) {
Product.apply(this, arguments);
this.category = 'food';
}
Food.prototype = new Product();
function Toy(name, price) {
Product.apply(this, arguments);
this.category = 'toy';
}
Toy.prototype = new Product();
var cheese = new Food('feta', 5);
console.log(cheese);
var fun = new Toy('robot', 40);
console.log(fun);
</script>
</head>
<body>
</body>
</html>
Weedpacket;10998526 wrote:If you create multiple registry objects you'd need some way of identifying which registry to look in for what you're wanting. If you group those values by their functionality (colours, fonts, etc.) then you'd also be able to add methods to those registry objects specific to working with the kinds of values they contain. And then you'll be wanting a prototype Colour object, etc. for individual colour objects to inherit methods from. Then the protoype Colour could also serve as the registry for colour objects....
So far, there are dozens of references to perhaps 10 or 15 colors:
obj.setBackgroundColor("#171717"); // this color might be referred to twenty times in various places
It therefore seems logical to centralize it somewhere to improve skinnability and reduce redundancy. I was thinking something like a color registry
if (!MY_APP) {
MY_APP = {};
}
MY_APP.colors = new Registry({
textColorDefault : "#171717",
textColorBlur : "#888888"
// etc....
});
I would have one central variable, MY_APP, from which dangle all of my applications globally needed values. The point of a registry is to prevent accidental changes of configuration values and to broadcast notifications when values change. For example a data table might re-render itself if we changed our color scheme from "iHeartPink" to "deathBeforeDishonor". We are also considering registries for prompts and text in our interface to make it language-agnostic, with all generic text being stored in language configuration files.
EDIT forgot MDN link.