DEV Community

Discussion on: An easy way to count elements in a JavaScript array

Collapse
 
jonrandy profile image
Jon Randy 🎖️

Extending prototypes in this way is dangerous and should be done with great care. Don't forget, you are extending a core part of JS that is relied on by pretty much everything else. There's no guarantee that your code will not conflict with other code that attempts to do something similar, or will be compatible with future updates of JS itself.

That said, there are ways to do this kind of thing safely. I recently wrote a library that can be used to help you safely extend native prototypes in this manner. I call it Metho. Take a look if you're interested 🙂

Collapse
 
lubiah profile image
Lucretius Biah

Hey @jonrandy metho seems really cool. I write an article about it soon