Saturday, April 18, 2009

How to convert your own javascript function into inbuilt function

How to convert your own JavaScript function into inbuilt function.
Ex:
String.prototype.ReplaceAll = function(stringToFind,stringToReplace)
{
var temp = this;
var index = temp.indexOf(stringToFind);
while(index != -1)
{
temp = temp.replace(stringToFind,stringToReplace);
index = temp.indexOf(stringToFind);
}
return temp;
}

If you include the highlighted part in front of your function you can use it like inbuilt function.
Ex: content.ReplaceAll(‘Script','JavaScript');
This will work within the application.

Courtesy: Senthil Kumar Muthusamy