Prototyping: Using prototype to extend objects
object.prototype.method=function;
/**
* Add equals function to String type
/
string.prototype.equals=function (str) {return
this==str.tostring ();
};
/**
* Adds the trim () function to string/
string.prototype.trim=function () {
//Gets the string object of the current calling method
var str= this;
Determines whether the first character of the current string is a space
while (Str.charat (0) = = "") {
//intercepting the head space and returning a new string
str=str.substring (1,str.length);
}
//Determine if the last character of the current string is not a space
while (Str.charat (str.length-1) = "") {
//intercept trailing spaces and return a new string
str= Str.substring (0,str.length-1);
}
Returns a string return
str;
/**
* Creates a weekday () function, adds it to the prototype of the Date object,
* Returns a String indicating the current date object is the day of the Week/
date.prototype.weekday= function () {
var day=this.getday ();
var arr=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
return Arr[day];