Are there any converters or techniques available for converting Javascript 1.7 code with its new language features to Javascript 1.6?
I’m most interested in iterator generators and the yield keyword. The script engine I use is only 1.6, but iterator generators would make for much better code. Writing it by hand seems complicated.
I’ve tried writing it in C#, decompiling with ILSpy, and porting that to Javascript by hand. But that’s a damn mess.
I’ve searched for such a convertor, but I’ve found nothing – perhaps due to the search terms being shared with irrelevant results in this case.
I think I’ve found a solution for you. Check out Traceur. It’s a ES6 transpiler, i.e. it converts ES6 code (with all of the ES6 upcoming stuff like generators, classes, modules,
yield) to ES5 code which is what today’s JS engines are able to interpret.Check it out here: https://github.com/google/traceur-compiler/
Language features page: https://github.com/google/traceur-compiler/wiki/LanguageFeatures
Notice how most of the stuff that Mozilla’s been adding to JavaScript 1.7+ is being standardized in the upcoming edition 6 of the ECMAScript standard. The current edition is edition 5 which already contains some of that stuff (e.g. Array iteration methods, the Object Extensibility API).