function test() {
test.count = test.count ? test.count+1 : 1
if (test.count % 2 === 0) {
console.log(2)
} else {
console.log(1)
}
}
test()
function countFn() {
let count = 0;
return function (...args) {
count++;
if (count & 1 === 1) return console.log(1);
console.log(2);
}
}
const testFn = countFn();
testFn(); // 1
testFn(); // 2
testFn(); // 1
testFn(); // 2
testFn(); // 1
testFn(); // 2
function* Print() {
while (true) {
yield console.log("1");
yield console.log("2");
}
}
let p = Print()
function myprint() {
p.next()
}
myprint()
myprint()
myprint()
}
责任编辑:Rex_08