function fmtHeading(level) {
stringtext = this.toString();
starttag = "<h" + level + ">";
endtag = "</h" + level + ">";
return starttag + stringtext + endtag;
}
String.prototype.heading = fmtHeading;
document.write("This is a heading!".heading(2));
Extend the String Method Example
Leave a Reply
You must be logged in to post a comment.