We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在 Generator 的语法那章里, 为了解释 next 方法传参的机制,给了一个例子,如下: ` function wrapper(generatorFunction) { return function (...args) { let generatorObject = generatorFunction(...args); generatorObject.next(); return generatorObject; }; }
const wrapped = wrapper(function* () { console.log(First input: ${yield}); return 'DONE'; });
First input: ${yield}
wrapped().next('hello!') `
我一直没想明白 wrapper 为什么还要返回一个 function ,就这个示例的目的而言写成下面这样不行吗:
`function wrapper(generatorFunction) { let generatorObject = generatorFunction(); generatorObject.next(); return generatorObject; }
wrapped.next('hello!') `
The text was updated successfully, but these errors were encountered:
这样简单一点,原文是构造一个 Generator API 兼容对象。
Sorry, something went wrong.
No branches or pull requests
在 Generator 的语法那章里, 为了解释 next 方法传参的机制,给了一个例子,如下:
`
function wrapper(generatorFunction) {
return function (...args) {
let generatorObject = generatorFunction(...args);
generatorObject.next();
return generatorObject;
};
}
const wrapped = wrapper(function* () {
console.log(
First input: ${yield}
);return 'DONE';
});
wrapped().next('hello!')
`
我一直没想明白 wrapper 为什么还要返回一个 function ,就这个示例的目的而言写成下面这样不行吗:
`function wrapper(generatorFunction) {
let generatorObject = generatorFunction();
generatorObject.next();
return generatorObject;
}
const wrapped = wrapper(function* () {
console.log(
First input: ${yield}
);return 'DONE';
});
wrapped.next('hello!')
`
The text was updated successfully, but these errors were encountered: