Unable to assign to the value of this
for a string prototype definition.
function testfunction(thisValue) {
thisValue = thisValue || this;
thisValue = "new test";
console.log(thisValue);
this = thisValue; // this throws error
}
Object.defineProperty(String.prototype, 'testfunction', { value: testfunction, enumerable: true });
let s = "i am a test"
s.testfunction()
for Array
object I am using this.push
. What is it for String
to assign a new value.