Open cb1kenobi opened 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.
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. ;)
@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.
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]';
};
@cb1kenobi yeah, it is. and i'm not bothered by it :)
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 wouldexport
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.