[英]JavaScript: How can i transpile array forEach, map, filter and etc to 'for' loop?
I wrote a code in valid es5, but some old enterprise system can't eat it as a module, it falls on 'array.forEach'. 我在有效的es5中编写了代码,但某些旧企业系统无法将其作为模块使用,而是落在“ array.forEach”上。 I don't now why, may be it runs some tests from the 90's or what else.
我现在不知道为什么,可能是从90年代开始进行了一些测试还是其他。
Is it posible to transpile it via babel or typescript? 是否可以通过babel或打字稿进行翻译?
// When this...
const a = ['abc', 'defghi'];
const b = a.filter(z => z.length > 3).forEach(z => console.log(z));
// ... becomes something like that
var a = ['abc', 'defghi'];
var b = [];
for (var i = 0; i < a.length; i++) {
if (a[i].length > 3) {
b.push(a[i]);
}
}
for (var i = 0; i < b.length; i++) {
console.log(b[i]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.