Return to Snippet

Revision: 2167
at January 8, 2007 07:59 by 1man


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

Initial URL


Initial Description
Simple extension of the string method using string.prototype.

Initial Title
Extend the String Method Example

Initial Tags
simple

Initial Language
JavaScript