I’ve created a superclass Control and a subclass LED. Control‘s initializer sets several attributes, like height, width, that sort of stuf. However, when I create an instance of LED – with the the proper data to fill the attributes that it should inherit – the inherited attributes don’t show up when logging the instance.
Here are the two constructors:
var Control = Class.create({
initialize: function(control){
log('info','Beginning creation of control using following control object.');
log('log',control);
// Define self to prevent conflicts with frameworks
if(!self){ var self = this; }
this.type = null;
this.size = { w: control.w, h: control.h };
this.position = { x: control.x, y: control.y };
this.color = control.color;
this.name = control.name;
this.active = false;
}
});
var LED = Class.create(Control,{
initialize: function($super){
$super;
this.type = "led";
}
});
I’ve created a small Heroku site to demonstrate: http://blazing-dusk-603.heroku.com/interfaces/16, if you open the console you’ll see a ton of logs, the one at the bottom is the instance of LED, without a size, position, color, name or active attribute.
This is the first time I use prototypejs to inherit so maybe I’ve misunderstood something, help would be appreciated, of course;)
If you want to call the superclass method, you probably should actually do so:
(or something like that). In any case, just mentioning the variable like your code does will have no effect.
edit — according to the Prototype docs, “$super” is a reference to the parent class function, so if you want to call it you’ll have to pass in a “control” parameter. I don’t know what that’s supposed to be, but your base class “initialize()” clearly wants it to be something non-null.
Really, it looks to me as if your subclass “initialize()” isn’t really following the API pattern of the parent class:
seems like it’s closer to what you want.