parkm / oldbpm

A JavaScript game where you shoot at bubbles.
0 stars 1 forks source link

Different Sub Constructors #54

Closed parkm closed 10 years ago

parkm commented 10 years ago

I noticed something odd while trying to implement some getter/setters for positions.

Object.defineProperty(GameObject.prototype, 'x', {
    get: function() { return this._x; },
    set: function(val) { console.log(val); this._x = val; },
});

When you start the game it'll log the current object positions, and this is the output I received:

0 
Town 
0 
0 
0 
Blacksmith 
0 
0 
105 
0 
Wizard 
0 
0 
273 
0 
400 
0 
My Quest 
0 
0 
32 
0 
Training 
0 
0 
32 

These strings come from buttons, so I did some experimentation and I think the problem has something to do with the utility method createClass. Specifically this:

    function Subclass() {
        Base.apply(this, arguments);
        def.apply(this, arguments);
    }

ui.Button inherits from ui.BasicButton but they have different constructors. The createClass code looks like you can only have constructors with the same arguments.