Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Encoding in javascript

1,558 views

Published on

  • Be the first to comment

  • Be the first to like this

Encoding in javascript

  1. 1.
  2. 2. Encoding in JavaScript<br />fahai [at] TaobaoUED<br />
  3. 3. ECMA 262 - §6<br />ECMAScript source text is represented as a sequence of characters in the Unicode character encoding, version 2.1 or later, using the UTF-16 transformation format. The text is expected to have been normalised to Unicode Normalised Form C (canonical composition), as described in Unicode Technical Report #15.<br />Conforming ECMAScript implementations are not required to perform any normalisation of text, or behave as though they were performing normalisation of text, themselves.<br />
  4. 4. SourceCharacter :: any Unicode character<br />
  5. 5. Rhino Book - §3.2<br />JavaScript programs are written using the Unicode character set.<br />Although the ECMAScript v3 standard allows Unicode characters anywhere in a JavaScript program, versions 1 and 2 of the standard allow Unicode characters only in comments and quoted string literals; all elements are restricted to the ASCII character set. Versions of JavaScript that predate ECMAScript standardization typically do not support Unicode at all.<br />
  6. 6. Code-point, not byte<br />
  7. 7. Example<br />var草泥马 = function() {<br />this.constructor.prototype.咆哮 = function(叫声) {<br /> alert(叫声);<br /> };<br />};<br />new 草泥马().咆哮("除尽天下河蟹日,家祭无忘告乃翁!");<br />
  8. 8. Example<br />alert(String.fromCharCode(35201, 21644, 35856, 65292, 35201, 26377, 29233));<br />
  9. 9. related functions<br />escape()<br />encodeURI()<br />encodeURIComponent()<br />
  10. 10. Reference<br />ECMAScript Specification - 3rd Edition<br />JavaScript - The Definition Guide - 5th Edition<br />
  11. 11. Thanks<br />

×