【发布时间】:2021-11-01 21:39:01
【问题描述】:
我在学习 yield 时遇到了这段代码,并想知道 yield 作为函数的参数会做什么。在这个地方看起来像一个荣耀的回归
export function * throttle(func, time) {
let timerID = null;
function throttled(arg) {
clearTimeout(timerID);
timerID = setTimeout(func.bind(window, arg), time); // what does this do????
}
while(true) throttled(yield);
}
export class GeneratorThrottle {
constuctor() {};
start = () => {
thr = throttle(console.log, 3000);
thr.next('');
};
toString = () => {
console.log(throttle);
console.log('start =', this.start);
};
};
【问题讨论】:
-
这能回答你的问题吗? What's the yield keyword in JavaScript?
标签: javascript async-await yield