Announcement

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

    Class extension

    Hi Isomorphic,

    As you guys know, I am working on adding Typescript definitions for SmartClient. I am having a hard time understanding inheritance though.

    I have to admit that I am a Java developper, Javascript is familiar but not in the intricacies of protypes etc.

    Obviously, the way you do inheritance is to define a new class and add properties to it, then calling the create method.

    If I want to subclass it in a more natural way, I need a way to connect my subclass (in the Typescript sense) to the superclass (defined with isc.DefineClass...). So right now I'm pretty lost. I guess there could be ways to connect prototypes together somehow, but I would need more help from you to have a plan on the proper method.

    Typescript extension:
    Code:
    class A{
    }
    
    class B extends A {
        constructor() {
            super();
        }
    }
    generates the following javascript

    Code:
    var __extends = this.__extends || function (d, b) {
        for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
        function __() { this.constructor = d; }
        __.prototype = b.prototype;
        d.prototype = new __();
    };
    var A = (function () {
        function A() {
        }
        return A;
    })();
    
    var B = (function (_super) {
        __extends(B, _super);
        function B() {
            _super.call(this);
        }
        return B;
    })(A);
    How could I make a subclass have its own set of functions while still retaining the super class properties?

    With the stuff I am working on, the superclass will be more easily understood, but the subclass still needs to be connected for everything to work.

    Thanks for your suggestions

    #2
    You are getting into some deep JavaScript voodoo and it's not clear that we can give you a quick "just do this" answer..

    It looks like TypeScript has the notion that the __extends method could be overridden. If so, you might override it so that it actually just calls SmartClient's ClassFactory.defineClass() method instead of directly trying to handle JavaScript prototype inheritance.

    Note that the implementation of super() generated by TypeScript looks extremely naive - it seems unlikely they are handling hard cases like recursive super calls, nor the yet harder case that we've never seen anyone but SmartClient handle: nested inter-recursion (two recursive chains of super calls going on in the same instance).

    This probably means that a SmartClient TypeScript wrapper should come with the advice to ignore TypeScript's super() and use SmartClient's.

    Comment

    Working...
    X