toHTML
1.6

toHTML(obj) -> String

如果 obj 具有 toHTML 方法,则调用 objtoHTML 方法,否则将 obj 作为 String.interpret 的参数然后调用该方法。返回调用这些方法后的返回值。

样例

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"