I am trying to extend the Array
object in Javascript exactly like this. I am trying to manipulate the values of the array (present in the this
object) using the prototype like in the function.
function clear() {
this = [];
}
Object.defineProperty(Array.prototype, 'clear', { value: clear, enumerable: true, });
It is giving me a error
Uncaught SyntaxError: Invalid left-hand side in assignment
I am aware that the this
is immutable. What is the workaround? I am not looking to create a new Object that emulates the Array constructor.