SOURCE

function* test() {
    for (let i = 0; i < 10; i++) {
        yield i;
    }

    return 11;
}

let todo = test();
console.log(todo.next());
console.log(todo.next());
console.log(todo.next());
console.log(todo.next());
console.log(todo.return(9));
console.log(todo.next());

new Promise((resolve, reject) => {
    console.log(111);
    reject("wobuzhidao")
}).then((res) => {
    console.log(res)
}, (err) => {
    console.log(err + "renshengchuchubudeyi")
})

let map = new Map();
map.set('name', 'jack');
map.set('age', 11);
map.set('sex', 'male');

let it = map[Symbol.iterator]();
console.log(it.next());
console.log(it.next());
let obj = {
    name: 'jack',
    age: 11,
    sex: 'male'
}
Object.defineProperties(obj, {
    name: {
        writable: false
    }
})
obj.name = 'test';
for (let [key, value] of Object.entries(obj)) {
    console.log(value)
}
let temp = Reflect.ownKeys(obj);
console.log(temp);

async function jsrun() {
    return 'ohaaha';
}
jsrun().then((res) => {
    console.log(res);
})

let tel = '18323456765';
console.log(tel.slice(-4).padStart(11, '*'))


/**
 * 异步迭代
 */
function getPromise(time) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve({
                value: time,
                done: false
            })
        }, time)
    })
}

let asyncArr = [getPromise(1000), getPromise(2000), getPromise(3000)];
asyncArr[Symbol.asyncIterator] = function() {
    let index = 0;
    return {
        next() {
            return index < asyncArr.length ? asyncArr[index++] : {
                value: undefined,
                done: true
            }
        }
    }
}

async function test2() {
    for await (let item of asyncArr) {
        console.log(item)
    }
}
test2();
console 命令行工具 X clear

                    
>
console