Issue #3006💬 AnsweredOpened September 7, 2020by ashercoren0 reactions

Don't loop over objects with a for in loop

快速解答by ashercoren

This caused a bug in our application since we are using some package that adds properties to the object prototype. When trying to initialize a grapes.js editor we get an error in the console.

Read full answer below ↓

Question

Version: 0.16.22

Are you able to reproduce the bug from the demo?

[-] Yes [ ] No

What is the expected behavior? Looping over objects should be done using Object.keys.forEach..., and not with a for-in loop.

Looping over objects with a for in loop will include properties that are inherited through the prototype chain. This behavior can lead to unexpected items in your for loop. More details can be found here.

Are you able to attach screenshots, screencasts or a live demo?

[ ] Yes (attach) [-] No

Answers (1)

ashercorenSeptember 7, 2020

This caused a bug in our application since we are using some package that adds properties to the object prototype. When trying to initialize a grapes.js editor we get an error in the console.

image

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.