Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How does this.Super() really work when called from a method?

    SmartClient Version: v10.0p_2015-12-02/Pro Deployment (built 2015-12-02)

    The documentation for the Class.Super instance method states that the method calls "the SuperClass implementation of an instance method" ...which from what I can tell is not actually true. In order to explain what I mean, see the following code snippet:

    Code:
    isc.defineClass("FirstTest", "Canvas").addProperties({
        height: 500,
        width: 500,
        backgroundColor: "red",
        initWidget: function () {
            this.Super("initWidget", arguments);
    
            console.log("first");               
        }
    });
    
    isc.defineClass("SecondTest", "FirstTest").addProperties({
        initWidget: function () {
            this.Super("initWidget", arguments);
    
            console.log("second");
        }
    });
    
    isc.SecondTest.create({
        initWidget: function () {
            this.Super("initWidget", arguments);
    
            console.log("third");
        }
    });
    When this runs, the console reads "first, second, third". Based on this result, the Super call within the initWidget of the SecondTest.create method is actually calling the initWidget on the default implementation for the class rather than the initWidget of it's super class. I actually know this for sure because I replace the console logs in each of the above initWidget definitions with 'this.getSuperClass()' - I get the result of "Canvas, FirstTest, FirstTest". So if Super really does call the super class implementation of the method, the original console logs should read "first, third" but that is just not the case.

    It is almost as if every time you create an instance of a class, it creates a subclass behind the scenes and considers the class that the instance is made up of as a super class. That is all fine and dandy, but don't you think that should be explained in the documentation for the Super method?

    This is not something that I am trying to throw in anyone's face or anything like that - it is just something that I guess I would like to confirm and get some explanation on.

    Thank you
    Last edited by efisch; 18 Aug 2016, 09:16. Reason: adding code elements

    #2
    Instances behave a lot like anonymous classes from Java or other languages that have such a concept: they allow method overrides, and Super calls the default implementation, which is pretty clearly what you would want. It's a good idea to clarify the docs on this point however - we'll do that.

    Comment

    Working...
    X