Create generators #3

Merged
TopchetoEU merged 5 commits from TopchetoEU/Generators into master 2023-08-25 21:44:39 +00:00
Showing only changes of commit 12093eda14 - Show all commits

View File

@ -166,8 +166,16 @@ setProps(Function, {
}, },
generator(func) { generator(func) {
if (typeof func !== 'function') throw new TypeError('Expected func to be function.'); if (typeof func !== 'function') throw new TypeError('Expected func to be function.');
return Object.assign(internals.makeGenerator(func), { const gen = internals.makeGenerator(func);
[Symbol.iterator]() { return this; } return (...args: any[]) => {
}); const it = gen(args);
return {
next: it.next,
return: it.return,
throw: it.throw,
[Symbol.iterator]() { return this; }
}
}
} }
}) })