var toUnicode = String.prototype.toUnicode =function () {
var _this = arguments[0] || this;
function f () {
return '&#'+arguments[0].charCodeAt(0) + ';';
}
return _this.replace(/[^\u00-\uFF]|\w/gmi, f);
};
var fromUnicode = String.prototype.fromUnicode = function () {
var _this = arguments[0] || this ;
function f () {
return String.fromCharCode(arguments[1]);
}
return _this.replace(/&#(\d*);/gmi , f);
}
var s='JavaScripts 中国';
s = toUnicode(s);
console.log(s);
s = s.fromUnicode();
console.log(s);