Extend the String Method Example

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));

source

Leave a Reply