Inherited Privileged Members
# Waldemar Horwat (16 years ago)
This proliferation of little function objects is one of the things that the various class proposals are addressing.
Waldemar
This proliferation of little function objects is one of the things that the various class proposals are addressing.
Waldemar
The strawman articles on Object Initialisers look very promising ( strawman:object_initialiser_extensions), but one issue I didn't see discussed is a solution to enable the inheritance of privileged members. Currently developers have to redefine accessor properties and methods on every constructor call to maintain a reference to the instance private variables. Ex:
function Foo(name, value){ // assume there was argument validation of some form. var _name = name, _value = value;
}
This approach can obviously leads to a potentially large amount of memory consumption. One workaround I've discovered to solve this issue is a pattern like the following:
var Foo = (function(){ var _refs = [], _props = [], _private = { get : function(o,n){ var i = _refs.indexOf(o); return ~i ? _props[i][n] : undefined; }, set : function(o,n,v){ var i = _refs.indexOf(o); if(~i) _props[i][n] = v;
"value") } }
})();
The verbosity is apparent. Has there been any discussion with Object Initialisers related to this type of problem?
Respectfully,
Michael Haufe