jhaynie / isometric-titanium

This is a simple prototype project / doc around a set of common and equal APIs to explore for Ti.Next.
5 stars 2 forks source link

Modules #4

Open cb1kenobi opened 10 years ago

cb1kenobi commented 10 years ago

CommonJS modules and require() exists due to the lack of a formal modules specification. In ES6, there will be a module spec.

In Ti.Next, the preferred way of loading modules would be using the import keyword and modules would export their APIs. It won't be long until ES6 modules catches on and be favored over CommonJS modules.

We still need require() to load CommonJS modules.

jhaynie commented 10 years ago

i want to support old style module require not just ES6 since it's still a long way off and frankly, it's pretty difficult over the node/commonjs style.

cb1kenobi commented 10 years ago

Definitely continue to support CommonJS modules.

Not sure I follow on the difficulty of ES6 modules. It looks different, but it's also Python-ish and readable.

module 'Window' {
    import 'ui/view' as View;

    export default class Window extends View {
        constructor(args) {
            //
        }
    };
}

ES6 may be a ways off, but it'll be here before you know it. ;)

jhaynie commented 10 years ago

@cb1kenobi it's simply a matter of subjective opinion and style. that above to me is a more complicated than:

module.exports = Window;
function Window() {
}

but of course, I like idea of classes, etc. I'm just not so bothered as others around JS prototypical inheritance model and common js.

cb1kenobi commented 10 years ago

Well, that's not an apples-to-apples comparison. This is:

var View = require('ti/ui/view');

module.exports = Window;

function Window(args) {
    View.apply(this, arguments);
}

Window.prototype = Object.create(View.prototype);
Window.prototype.constructor = Window;

Window.prototype.toString = function () {
    return '[object Window]';
};
jhaynie commented 10 years ago

@cb1kenobi yeah, it is. and i'm not bothered by it :)