Javascript escapeHtml, unescapeHtml 함수

String.prototype.escapeHtml = function(){
  return this.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/\"/g, "&quot;");
};

String.prototype.unescapeHtml = function(){
  return this.replace(/&amp;/g, "&").replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, "\"");
};


Example
"<div>하이~~</div>".escapeHtml();                  // &lt;div&gt;하이~~&lt;/div&gt;

"&lt;div&gt;하이~~&lt;/div&gt;".unescapeHtml();    // <div>하이~~</div>


prototype : 원형, 견본, 전형, 선조, 원조