We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

1man on 01/08/07


Tagged

simple heading tutorial


Versions (?)


Who likes this?

1 person has marked this snippet as a favorite

vali29


Extend the String Method Example


Published in: JavaScript 


Simple extension of the string method using string.prototype.

  1. function fmtHeading(level) {
  2. stringtext = this.toString();
  3. starttag = "<h" + level + ">";
  4. endtag = "</h" + level + ">";
  5. return starttag + stringtext + endtag;
  6. }
  7.  
  8. String.prototype.heading = fmtHeading;
  9. document.write("This is a heading!".heading(2));

Report this snippet 

You need to login to post a comment.