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
如果我们需要使用 for of 遍历一个对象,需要为对象实现相应 Symbol.iterator 接口实现,例如下面这种方式:
function objectIterator() { const keys = Object.keys(this) let index = 0 return { next: () => { const done = index >= keys.length const value = done ? undefined : this[keys[index]] index++ return { done, value } } } } Object.prototype[Symbol.iterator] = objectIterator const obj = { key: '1', value: '2' } for (const iterator of obj) { console.log(iterator) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
如果我们需要使用 for of 遍历一个对象,需要为对象实现相应 Symbol.iterator 接口实现,例如下面这种方式:
The text was updated successfully, but these errors were encountered: