locked
Inheritance In Javascript (Visual studio 2012 pro)

    Question

  • var Robot = WinJS.Class.define(
        null,
        {
            makeNoise: function () {
                return "beep";
            }
        }
    );
    
    var Roomba = WinJS.Class.derive(
        Robot,
        null,
        {
            makeNoise: function () {
                return this._super.makeNoise() + "!";
            }
        }
    );
    
    var myRobot = new Roomba();
    console.log(myRobot.makeNoise()); // Writes "beep!"

    Like I know " WinJS.Class.derive() method => two magic properties  named constructor and _super" , but I get error in the code "0x800a138f - JavaScript runtime error: Unable to get property 'makeNoise' of undefined or null reference".

    I don't know reason why??? How do I use the "_super"?

    I need a help.

    Wednesday, September 05, 2012 12:57 PM

Answers

  • _super was removed between RC and RTM - turned out there was a potential infinite recursion in there. If the docs still mention _super, that's a bug in the docs, sorry!

    To work around it, explicitly call the method from your "base class". Instead of:

    return this._super.makeNoise() + "!";

    do:

    return Robot.prototype.makeNoise.call(this) + "!";

    Wednesday, September 05, 2012 3:52 PM

All replies

  • _super was removed between RC and RTM - turned out there was a potential infinite recursion in there. If the docs still mention _super, that's a bug in the docs, sorry!

    To work around it, explicitly call the method from your "base class". Instead of:

    return this._super.makeNoise() + "!";

    do:

    return Robot.prototype.makeNoise.call(this) + "!";

    Wednesday, September 05, 2012 3:52 PM
  • Thank, I got it.

    Wednesday, September 05, 2012 4:29 PM