toHTML
1.6

toHTML(obj) -> String

Returns the return value of obj’s toHTML method if it exists, else runs obj through String.interpret.

Examples


var Bookmark = Class.create({
  initialize: function(name, url) {
    this.name = name;
    this.url = url;
  },

  toHTML: function() {
    return '<a href="#{url}">#{name}</a>'.interpolate(this);
  }
});

var api = new Bookmark('Prototype API', 'http://prototypejs.org/api');

Object.toHTML(api);
//-> '<a href="http://prototypejs.org/api">Prototype API</a>'

Object.toHTML("Hello world!");
//-> "Hello world!"

Object.toHTML();
//-> ""

Object.toHTML(null);
//-> ""

Object.toHTML(undefined);
//-> ""

Object.toHTML(true);
//-> "true"

Object.toHTML(false);
//-> "false"

Object.toHTML(123);
//-> "123"