Answer Question
How to set a String object's string value in JavaScript from within its methods?
A string is a string but a string is also a String Object in JavaScript.
Therefore we can prototype it - I mean add methods to it using String.prototype.
The question: How can I set the string's simple value from within one of it's methods?
Imagine I want to add something to a string using a self-written method - something like this;
var x = "Wayne's";
x.addSomething("World");
alert(x); // This should popup the message "Wayne's World";
I've tried with something like this method:
String.prototype.addSomething = function(something)
{
this = this + " " + something; // This doesn't work. Can't assign a value to 'this'
}
How do I assign the new value to the string?
Thanks,
Jakob
TEXT
Uploading file and scanning for virus...
Please Wait