文章转载自:https://github.com/zhongsp
建议您直接跳转到上面的网址查看最新版本。
可迭代性
for..of 语句
let someArray = [1, "string", false];
for (let entry of someArray) {
console.log(entry);
for..of vs. for..in 语句
let list = [4, 5, 6];
for (let i in list) {
console.log(i);
let pets = new Set(["Cat", "Dog", "Hamster"]);
pets["species"] = "mammals";
for (let pet in pets) {
console.log(pet);
代码生成
目标为 ES5 和 ES3
let numbers = [1, 2, 3];
for (let num of numbers) {
console.log(num);
}
var numbers = [1, 2, 3];
for (var _i = 0; _i < numbers.length; _i++) {
var num = numbers[_i];
console.log(num);
}
目标为 ECMAScript 2015 或更高
|
请发表评论