Posts

Showing posts with the label Relator

a new Relator object plus unshared private variables

This is a Robert Nyman 's post dedicated reply, about JavaScript inheritance and alternatives and private variables . First of all, I would like to say thanks to Robert for both interesting articles He is writing about JS inheritance, and a link to a personal comment which aim was to bring there my "old" documentation about classical JavaScript inheritance and usage of prototype, closures, and public, privileged, or private, scope when we create a constructor. About Last Rob's post talk about private variables, describing them as shared, if present outside the constructor, and valid only for singleton instances. This is true, and could cause a lot of headache if we are not truly understanding closures and prototype shared methods behaviour, but there is a way to use this peculiarity about shared private variables to create dedicated private variables. Before I will write about it, let's look into a generic shared private variable example: Click = function(){ ...

JavaScript Relator Object, aka unobtrusive informations

Have you never though about add, modify, or remove a generic information from a variable, and without changing variable itself? This is all about what my last simple creation does. Relator Object Concept The main purpose for this object is to associate every kind of information, value, or function, into a generic variable, whatever it is, and without modifying its native state. To obtain this result, I have used a 1:1 relationship between a stack that will contain every stored variable, and another one that will contain related objects. Stack = [1, 2, 3]; RelatedObject = [{}, {}, {}]; // add a property RelatedObject[Stack.indexOf(2)].description = "Number 2"; // remove a property Stack.splice(0, 1); RelatedObject.splice(0, 1); // situation Stack = [2, 3]; RelatedObject = [{description:"Number 2"}, {}]; Using above strategy we obtain 2 benefits: The Stack does not cause memory leaks both Stack and RelatedObject are alw...