Closed pocesar closed 11 years ago
Hi Paulo,
Apology for the late reply. Possibly you found some workaround. I implemented this.$super() before (you can find in previous version like at https://github.com/tnhu/jsface/blob/v2.0.2/jsface.js). It was convenient but fact is to keep track of the inheritance, it's a huge performance lost.
Not exact a solution but I use to declare classes under a namespace, which helps to avoid introducing globals. In order to add classes in the factory's repo, I use $ready plugin. For example:
PL = {};
PL.Factory = Class(function() {
var repository = {};
return {
$ready: function(clazz, parent, api) {
var name;
// clazz is a sub-class
if (this !== clazz) {
name = api.name;
if (name && jsface.isString(name) && !repository[name]) {
repository[name] = clazz;
}
}
}
};
});
PL.Core = Class(PL.Factory, {
name: 'Core',
mystuff: function(){
}
});
PL.MyClass = Class(PL.Factory, {
name: 'MyClass',
mystuff: function(){
PL.MyClass.$superp.mystuff.call(this);
}
});
suppose I have two classes (in different files, in Node):
now in a second file I do:
I want the user to drop the need to use variables, and define a class without having to assign it, because I'm using a repository pattern, when factory is called, a new class is instantiated inside a private
repository
object automatically.factory
is merely a wrapper:How can I go around this? How can I make it so the "this" points to the current class?