jsx / JSX

JSX - a faster, safer, easier JavaScript
http://jsx.github.io/
MIT License
1.47k stars 102 forks source link

Exported classes should be extendable from JavaScript #153

Open kazuho opened 11 years ago

kazuho commented 11 years ago

As @shibukawa suggested, exported classes should be extendable by using ordinary JavaScript.

note: the example right below is known not to work, for the current proposal see https://github.com/jsx/JSX/issues/153#issuecomment-17391593

// in foo.jsx
__export__ class Base {
    function say() : void {
        log "base";
    }
}
// in JavaScript
var Base = JSX.require("foo.jsx").Base;
function Derived() {
}
Derived.prototype = new Base;
Derived.prototype.say = function () {
    log "derived";
};
kazuho commented 11 years ago

Sorry to change my words but it is impossible to extend a JSX class using ordinary JavaScript (see the example in prev. comment; the method say belonging to an instance is sometimes known to be __export__ed and sometimes not). We need to provide a helper function.

kazuho commented 11 years ago

The helper function for extending JSX classes in JavaScript may look like follows:

var Base = JSX.require("foo.jsx");

var Derived = Base.$extend({
    constructor: function () {
        ...
    },
    toString: function () {
        ...
    },
});
gfx commented 11 years ago

+1 for helper function