+ 1
How to avoid method inside class from getting overriden outside the class?
I just found this hack for google crome Dinojump, where we override the gameOver function of the game instance and set it to empty function to avoid the gameOver function from getting implemented. Is there a way of avoiding it? https://code.sololearn.com/WV9716plmNaT/?ref=app
3 Respostas
+ 2
You can use Object.freeze (for the whole object) or Object.defineProperty (set writable and configurable to false)
https://stackoverflow.com/questions/41639501/prevent-overriding-javascript-function
0
Or you can define your method as a Symbol.
https://code.sololearn.com/WvLArjA8FaP5/?ref=app
0
But of course, doing so doesn't prevent from defining new method. So in order to prevent defining new method you should follow above mentioned steps. With Symbol method you just can make sure that you'll never override it with another property.