String.prototype.left = function (n) {
if (n > this.length)
return this;
return this.substr(0, n);
}
String.prototype.right = function(n) {
if (n > this.length)
return this;
return this.substr(this.length-n, n);
}
And they would be used like this:
alert("Hello".right(2)) // Yields lo
alert("Hello".left(4)) // Yields Hell