class method Object.toHTML

View source on GitHub →

Object.toHTML(object) → String
  • object (Object) – The object to convert to HTML.

Converts the object to its HTML representation.

Returns the return value of object's toHTML method if it exists; else runs object 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"