Encoding in javascript

  • 1,299 views
Uploaded on

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,299
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
8
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1.
  • 2. Encoding in JavaScript
    fahai [at] TaobaoUED
  • 3. ECMA 262 - §6
    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.
    Conforming ECMAScript implementations are not required to perform any normalisation of text, or behave as though they were performing normalisation of text, themselves.
  • 4. SourceCharacter :: any Unicode character
  • 5. Rhino Book - §3.2
    JavaScript programs are written using the Unicode character set.
    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.
  • 6. Code-point, not byte
  • 7. Example
    var草泥马 = function() {
    this.constructor.prototype.咆哮 = function(叫声) {
    alert(叫声);
    };
    };
    new 草泥马().咆哮("除尽天下河蟹日,家祭无忘告乃翁!");
  • 8. Example
    alert(String.fromCharCode(35201, 21644, 35856, 65292, 35201, 26377, 29233));
  • 9. related functions
    escape()
    encodeURI()
    encodeURIComponent()
  • 10. Reference
    ECMAScript Specification - 3rd Edition
    JavaScript - The Definition Guide - 5th Edition
  • 11. Thanks