Having trouble assigning a new value to the this
keyword within 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()
When it comes to the Array
object, I am familiar with using this.push
. However, I am unsure how to assign a new value to the String
.