how to use vanilla js iterate the Symbol Object All In One
2022/9/2 6:22:54
本文主要是介绍how to use vanilla js iterate the Symbol Object All In One,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
how to use vanilla js iterate the Symbol Object All In One
bug ❌
Uncaught TypeError: UIComponents is not iterable
import * as UIComponents from './index' console.log(`UIComponents =`, UIComponents); // UIComponents = Module {Symbol(Symbol.toStringTag): 'Module'} export const UIComponentsInstall = { // 钩子函数 install: (app: App) => { // Uncaught TypeError: UIComponents is not iterable ❌ for (const component of UIComponents) { // 把组件挂载到 Vue 上 app.component(component.name, component); } } }
solution ✅
lodash-es
$ yarn add -D lodash-es @types/lodash-es
loadsh forEach
import * as UIComponents from './index' export const UIComponentsInstall = { // 钩子函数 install: (app: App) => { forEach(UIComponents, (component) => { // 把组件挂载到 Vue 上 app.component(component.name, component); }) } }
???
let str = "Hello"; // does the same as // for (let char of str) alert(char); let iterator = str[Symbol.iterator](); while (true) { let result = iterator.next(); if (result.done) break; alert(result.value); // outputs characters one by one }
https://javascript.info/iterable
https://www.youtube.com/watch?v=CM_oBrnB4Vk&ab_channel=codebubb
https://www.youtube.com/watch?v=2oU-DfdWM0c&ab_channel=dcode
refs
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Symbol/iterator
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载
这篇关于how to use vanilla js iterate the Symbol Object All In One的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-30[OIDC in Action] 2. 基于OIDC(OpenID Connect)的SSO(纯JS客户端)
- 2024-03-29terraform jsonencode
- 2024-03-13vuex-persist
- 2024-03-11icons for vue
- 2024-03-07breadcrumbs react js
- 2024-03-06react login page example
- 2024-03-06react router uselocation
- 2024-03-04postgres jsonb_set
- 2024-03-01react native uuid
- 2024-02-29vuejs sidebar