Extended the javascript string operator

If you want to extend a javascript object:

// Define the function to do what you want
function first3char() {
    return this.substr(0,3); // 'this' will be the variable that's passed in
}

// Extend the javascript string operator
String.prototype.first3=first3char;

// Call your extension using the string 'abc123'
"abc123".first3();


Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
 
Logged IP: 3.234.143.26
To prevent spam please submit by clicking the kitten: