#ads_1
String.prototype.toEscape = function(){
var result = '';
for(var i=0; i<str.length; i++){
var c = str.charCodeAt(i).toString(16);
if(escape(str.charAt(i)).length < 6){
result += '\\x' + c;
}else{
result += '\\u' + c;
}
}
return result;
}
<사용법>
str = "alert('안녕하세요 漢子입니다 ※');";
document.write(str.toEscape());
<결과>
\x61\x6c\x65\x72\x74\x28\x27\uc548\ub155\ud558\uc138\uc694\x20\u6f22\u5b50\uc785\ub2c8\ub2e4\x20\u203b\x27\x29\x3b
#ads_2