ondras / rot.js

ROguelike Toolkit in JavaScript. Cool dungeon-related stuff, interactive manual, documentation, tests!
https://ondras.github.io/rot.js/hp/
BSD 3-Clause "New" or "Revised" License
2.33k stars 254 forks source link

suggest making Array.prototype.random and Array.prototype.randomize non-enumerable. #129

Closed infiniteperplexity closed 3 years ago

infiniteperplexity commented 6 years ago

i.e.

Object.defineProperty(Array.prototype, 'random', { enumerable: false });

Object.defineProperty(Array.prototype, 'randomize', { enumerable: false });

ondras commented 6 years ago

Good idea!

jcubic commented 3 years ago

@ondras will you accept a PR, I can add this. Got an issue yesterday when the other library failed to run because it uses for..in on Array. Need to use a hack to temporarily remove the polluted properties while executing function from the other library.

The library was filget.js when loading a font. I've already added PR that that library to add hasOwnProperty.

ondras commented 3 years ago

@ondras will you accept a PR, I can add this.

Yes, please. I am completely out of time these days :-(

I've already added PR that that library to add hasOwnProperty.

A better solution IMHO would be to stop iterating arrays with for..in and use other looping approaches.

jcubic commented 3 years ago

A better solution IMHO would be to stop iterating arrays with for..in and use other looping approaches.

Yes, but this is not my code that does that.

jcubic commented 3 years ago

I think that this is no longer valid. The library doesn't pollute Array prototype anymore. In my case, I was using an older version of the library.

I think this can be closed.

jcubic commented 3 years ago

I think that it got removed when the project was migrated to TS. Because the last commit that had Array.prototype is 2392039cecc8de3a97c09ec94d2bf6286e130fc0 cleanup when _old file was deleted.