Extending prototype of Array causes errors in 'dom/update-dom.ts' and 'ssr/index.ts'
See original GitHub issueExtending the Array.prototype with additional functions, causes the ‘updateDOM’ and ‘renderHeadToString’ functions to crash as “for…in” is used to iterate through the arrays instead of “for…of”. Maybe you could use Array.forEach if you need an element of the array and the index of it?
Array.prototype.isEmpty = function (func = null) { func = func != null ? func : (_ => true); return !this.some(func); };
Above is one example of the functions we use in our packages, which makes those ‘updateDOM’ and ‘renderHeadToString’ functions crash (but we have many more handy functions, also for other types).
Issue Analytics
- State:
- Created a year ago
- Comments:7
Top Results From Across the Web
[5.10.1] Extending Array.prototype – `Cannot read property ...
Hi there! TL;DR: code sample I have a: Issue: Provide error messages including stacktrace mobx.module.js:2199 Uncaught TypeError: Cannot ...
Read more >How to properly extend Array prototype in Typescript 4.0.3?
Array is defined as an interface not a type. Interfaces in typescript are open ended and can be added to by multiple declarations....
Read more >Array.prototype.map() - JavaScript - MDN Web Docs
The map() method creates a new array populated with the results of calling a provided function on every element in the calling array....
Read more >Extending built-in classes
Built-in objects have their own static methods, for instance Object.keys , Array.isArray etc. As we already know, native classes extend each ...
Read more >How to extend Array.prototype in TypeScript
Create a .d.ts file and add an interface that extends Array . Add types for the methods you intend to use on array...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
yes 😃
If you would use
for..of
, we would not have this problem, and your code would be more legible. You would get code like:for (const tag of head.hooks['resolved:tags']) await tag(headTags)
instead of
for (const h in head.hooks['resolved:tags']) await head.hooks['resolved:tags'][h](headTags)
This is what I get in our Nuxt 3 module code.