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

Allow user to extend the Array prototype #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Allow user to extend the Array prototype #126

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Dec 2, 2019

As-is, modifications to the array prototype will break the ability to create construction sites near the edges of rooms, where it would otherwise be allowed.

As-is, modifications to the array prototype will break the ability to create construction sites near the edges of rooms, where it would otherwise be allowed.
@o4kapuk o4kapuk self-assigned this Dec 19, 2019
@o4kapuk
Copy link
Contributor

o4kapuk commented Dec 19, 2019

@Dignissi could you please provide any reproduction code for the mentioned breaking?

@ghost
Copy link
Author

ghost commented Dec 20, 2019

@o4kapuk

Array.prototype.peek = function() { return this[this.length-1]; }
Game.rooms["E42S2"].createConstructionSite(1,43,STRUCTURE_WALL);

1,43 is a legal position (not adjacent to exit), for which createConstructionSite() is returning -7 with the prototype change, and 0 without

@madrang
Copy link

madrang commented Jun 8, 2022

Extending Array with an enumerable property will make it show as a Key on all child arrays created later.
To fix this the engine should not change, but the function added should not be enumerable.

// Use the Object.defineProperty to make it not enumerable.
Object.defineProperty(Array.prototype, 'peek', {
    enumerable: false,  // this will make it not iterable
    get: function() { return this[this.length-1]; }
});

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

Successfully merging this pull request may close these issues.

2 participants