Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throws 'userColors[color].toLowerCase() is not a function' #13

Closed
andrewwalters opened this issue Jun 15, 2018 · 1 comment
Closed

throws 'userColors[color].toLowerCase() is not a function' #13

andrewwalters opened this issue Jun 15, 2018 · 1 comment

Comments

@andrewwalters
Copy link

If my program contains custom properties for Array, then CheckInput() throws a "TypeError: userColors[color].toLowerCase() is not a function" error. This is because for (var color in userColors) iterates over both the array elements and the custom properties. I believe changing for...in to for...of will fix it. To reproduce:

Array.prototype.foo = () => { return 0; };
const cfonts = require('cfonts');
cfonts.say('Hello', { colors: [ 'green' ] });
@dominikwilkowski
Copy link
Owner

Hi @andrewwalters
Changing the prototype of native objects you don't have ownership over is a big no-no and largely considered an anti pattern because it can effect other code like libraries ironically illustrated by your submitted issue. But I know that some old code bases did this and we don't always have the luxury of rebuilding everything or working with modern code so I had a look and since my code here was a bit old I decided to rewrite the loops from for in to forEach which make much more sense here :)
That will incidentally also fix your issue and is now live with v2.1.3.

Hope it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants