Closed sylouuu closed 11 years ago
Hi sylouuu, child classes do not automatically run the constructor of their parent. You need to run it manually. You could either do this:
var Child = Parent.subclass({
constructor : function() {
Parent.prototype.constructor.apply(this, arguments);
}
});
or this:
var Child = Parent.subclass({
constructor : function() {
Child.parent.constructor.apply(this, arguments);
}
});
In both cases, doing a
var child = new Child();
alert(child.name);
Will give an alertbox with 'syl'
var Child = Parent.subclass({
constructor : function() {
Parent.apply(this, arguments);
}
});
// use parent constructor by default
var createSubclass = _.createSubclass;
_.createSubclass = function(props, events) {
if (!props.hasOwnProperty('constructor'))
props.constructor = function() {
props.superclass.apply(this, arguments)
};
return createSubclass.call(this, props, events);
};
Hi!
I'm trying to make a parent/child link with Stapes.js.
Here is my code:
How to access to the parent's name property from the child class? fiddle here.
Any ideas guys?
Thanks, regards.