0

gameclosure uses the class structure for code modulation
example code 1:

exports = Class(GC.Application, function() {
  //Code here
});

I was trying to look for the code inside the Class varible, I found a Class varible declartion in jsio/packages/base.js

exports.Class = function(name, parent, proto) {
    return exports.__class__(
        function() { 
          return this.init && this.init.apply(this, arguments); 
        }, 
        name, parent, proto);
}

but, this function is not syntactically the same as to be used by the example code mentioned above. so, my question is where is the class varibale located. and what is the use for the jsio/packages/base.js class variable? also, how can i call the super class methods from the extended class?

isnvi23h4
  • 1,910
  • 1
  • 27
  • 45
  • What do you mean by "*this function is not syntactically the same as to be used by the example code*"? – Bergi Nov 10 '15 at 16:46
  • @Bergi the exports.class function is getting the parent class as the second parameter while in the example the base class is passed in the first parameter. – isnvi23h4 Nov 10 '15 at 16:47
  • It might well be just overloaded, and `name` is optional. Check what `__class__` does, I'm pretty sure if shifts the arguments if `name` is not a string. – Bergi Nov 10 '15 at 16:53
  • @Bergi yes, you are right, the __class__ function is shifting the value – isnvi23h4 Nov 10 '15 at 17:04

1 Answers1

0

I Think you have all ready found the answer,incase you havent found the answer to the second question. this is how you can call a super class method from the base class.

var Vehicle = Class(function () {
    this.init = function (wheels) {
        this.wheels = wheels;
    };
});

var Truck = Class(Vehicle, function (supr) {

    this.init = function (hp, wheels) {
        supr(this, "init", [wheels]);
        this.horsepower = hp;
    };

    this.printInfo = function () {
        $('#result').html('I am a truck and I have ' + this.wheels +
                ' wheels and ' + this.horsepower + ' hp.');
    };
});

var t = new Truck(350, 4);
t.printInfo();
isnvi23h4
  • 1,910
  • 1
  • 27
  • 45