traceur

Should I use Traceur instead of Typescript to target ES5 but be ready for ES6

会有一股神秘感。 提交于 2019-12-03 05:02:49
问题 I'm working on a large code base that could benefit from Typescript, but since eventually the world will be moving to ES6, should I steer the development towards Traceur? I don't want to change Typescript implementations in order to target ES6 (when is ready), so my feeling now is to go ahead with Traceur. Can anyone advise? 回答1: I definitely do not agree with the opinion that TypeScript and Traceur are so different, TypeScript is ES5 with types and Traceur is just about ES6. On the one hand

angularjs http interceptor class (ES6) loses binding to 'this'

自闭症网瘾萝莉.ら 提交于 2019-12-03 01:55:59
I am building and AngularJS app using ES6 classes with traceur transpiling to ES5 in AMD format. in my module I import the interceptor class and register it as a service, and then register this service with the $httpProvider.interceptors in module.config: var commonModule = angular.module(moduleName, [constants.name]); import authenticationInterceptor from './authentication/authentication.interceptor'; commonModule.service('authenticationInterceptor', authenticationInterceptor); commonModule.config( $httpProvider => { $httpProvider.interceptors.push('authenticationInterceptor'); }); My

Should I use Traceur instead of Typescript to target ES5 but be ready for ES6

别来无恙 提交于 2019-12-02 19:22:35
I'm working on a large code base that could benefit from Typescript, but since eventually the world will be moving to ES6, should I steer the development towards Traceur? I don't want to change Typescript implementations in order to target ES6 (when is ready), so my feeling now is to go ahead with Traceur. Can anyone advise? Thaumant I definitely do not agree with the opinion that TypeScript and Traceur are so different, TypeScript is ES5 with types and Traceur is just about ES6. On the one hand there is an ES6 compatible TypeScript 2.0 in progress . On the other hand there are a couple of

Extending Array with ES6 classes

十年热恋 提交于 2019-11-29 03:12:12
I have heard that ES6 now finally permits subclassing Array. Here's an example given by class Stack extends Array { constructor() { super() } top() { return this[this.length - 1]; } } var s = new Stack(); s.push("world"); s.push("hello"); console.log(s.top()); // "hello" console.log(s.length); // 2 Sure, that works. But in Traceur at least, setting the length explicitly does not truncate the array. And when printing via console.log, the output is in object form rather than array form, suggesting that somebody is not looking at it as a "real" array. Is this a problem with how Traceur implements

Extending Promises in ES6

此生再无相见时 提交于 2019-11-28 10:44:56
I am trying to extend Promise: class PersistedPromise extends Promise { } Then call the static resolve on the derived class to directly create a resolved promise: PersistedPromise.resolve(1) In traceur, this yields: ModuleEvaluationError: #<PersistedPromise> is not a promise at new PersistedPromise (~rtm/gen/promise.js:6:57) at Function.resolve (native) In Babel (run as babel-node --experimental promise.js ) it results in: Promise.apply(this, arguments); ^ TypeError: [object Object] is not a promise at new PersistedPromise (~rtm/gen/promise.js:1:23) at Function.resolve (native) ... I was

How to implement private method in ES6 class with Traceur [duplicate]

醉酒当歌 提交于 2019-11-27 10:35:00
This question already has an answer here: Private properties in JavaScript ES6 classes 35 answers I use Traceur Compiler to have advantage with ES6 features now. I want to implement this stuff from ES5: function Animal() { var self = this, sayHi; sayHi = function() { self.hi(); }; this.hi = function() {/* ... */} } Currently traceur does not support private and public keywords ( from harmony ). And ES6 class syntax does not allow to use simple var (or let ) statements in class body. The only way that I am find is to simulate privates before class declaration. Something like: var sayHi =

Nested ES6 classes?

淺唱寂寞╮ 提交于 2019-11-27 08:33:26
It seems possible to nest a class in a constructor which can then be instantiated from anywhere within the class, is this official? [EDIT] E.g., class C { constructor() { class D { constructor() { } } } method() { var a = new D(); // works fine } } //var a = new D(); // fails in outer scope The traceur generated JS https://google.github.io/traceur-compiler/demo/repl.html $traceurRuntime.ModuleStore.getAnonymousModule(function() { "use strict"; var C = function C() { var D = function D() {}; ($traceurRuntime.createClass)(D, {}, {}); }; ($traceurRuntime.createClass)(C, {method: function() { var

Extending Promises in ES6

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 03:47:06
问题 I am trying to extend Promise: class PersistedPromise extends Promise { } Then call the static resolve on the derived class to directly create a resolved promise: PersistedPromise.resolve(1) In traceur, this yields: ModuleEvaluationError: #<PersistedPromise> is not a promise at new PersistedPromise (~rtm/gen/promise.js:6:57) at Function.resolve (native) In Babel (run as babel-node --experimental promise.js ) it results in: Promise.apply(this, arguments); ^ TypeError: [object Object] is not a

Get the class name of ES6 class instance

旧城冷巷雨未停 提交于 2019-11-26 21:46:18
Are there any 'harmonious' ways to get the class name from ES6 class instance? Other than someClassInstance.constructor.name Currently I'm counting on Traceur implementation. And it seems that Babel has a polyfill for Function.name while Traceur doesn't. To sum it all up: there was no other way in ES6/ES2015/Harmony, and nothing is expected ATM in ES.Next. It may provide useful patterns for unminified server-side applications but is unwanted in applications meant for browser/desktop/mobile. Babel uses core-js to polyfill Function.name , it should be loaded manually for Traceur and TypeScript

How to implement private method in ES6 class with Traceur [duplicate]

旧时模样 提交于 2019-11-26 17:57:27
问题 This question already has an answer here: Private properties in JavaScript ES6 classes 35 answers I use Traceur Compiler to have advantage with ES6 features now. I want to implement this stuff from ES5: function Animal() { var self = this, sayHi; sayHi = function() { self.hi(); }; this.hi = function() {/* ... */} } Currently traceur does not support private and public keywords (from harmony). And ES6 class syntax does not allow to use simple var (or let ) statements in class body. The only