JavaScript Ninja – Unicode – String.prototype.fromCharCode Fix To Allow More Than-2 Bytes Unicode Chars Directly (A.K.A Unicode-Surrogate-Pair)

String.from_char_code__with_unicode_surrogate_pair_support = function(char_code){ "use strict";
  var surrogate1, surrogate2;

  if(char_code <= 0xFFFF) return String.fromCharCode(char_code);

  char_code  = char_code - 0x10000;
  surrogate1 = 0xD800 + (char_code >> 10);
  surrogate2 = 0xDC00 + (char_code &  0x3FF);
  return String.fromCharCode([surrogate1, surrogate2]);
};

A seamless solution is to secretly override (one time..)
fromCharCode method.

/* the magic of scope :] */
(function(){ "use strict";
  var original_reference = String.fromCharCode;
  
  function fromCharCodeFixed(code){
    if(code <= 0xFFFF) return original_reference(code);
  
    code = code - 0x10000;
    return original_reference(0xD800 + (code >> 10)
                             ,0xDC00 + (code &  0x3FF)
                             );
  }

  String.fromCharCode = fromCharCodeFixed;                        //override
  String.fromCharCode.original_reference = original_reference;    //allow access to original reference (optional)
}());

Do it only once. although it can not really harm anything
other than create a recursive infinite-loop to itself :]
You can check the existence of original_reference to make sure not to run the block again… :]]