I'm trying to use: Simple Javascript Inheritance by John Resig
What I find really limited is the fact that the variables are not private to an instance of the object. This simple fact is one of the key factor for which a person would choose to adopt this kind of approach.
I've seen in the comments in the linked page that someone is suggesting the following:
init: function() {
// Private var
var _div = $( div );
// Priviledged method accesses private var
this.getDiv = function () { return _div; }
this.setDiv = function (div) { _div = div; }
// other initialization stuff
}
I have some doubts about this approach:
- In the class I'm declaring, will I need to access this variables always through setter and getter?
- How can I use this variables in the definition of inner functions?
Let's say for example:
node.append("title").text(function(d) { /* use private variable */ });
Has someone overcame this limitation?
Thanks and best regards
Sergio