question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extending prototype of Array causes errors in 'dom/update-dom.ts' and 'ssr/index.ts'

See original GitHub issue

Extending 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:closed
  • Created a year ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
RattleSneekcommented, Nov 2, 2022

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)

1reaction
RattleSneekcommented, Nov 2, 2022

Screenshot 2022-11-02 121114

This is what I get in our Nuxt 3 module code.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found