tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

subclassing.js (940B)


      1 // Copyright 2011-2012 Norbert Lindenberg. All rights reserved.
      2 // Copyright 2012 Mozilla Corporation. All rights reserved.
      3 // This code is governed by the BSD license found in the LICENSE file.
      4 
      5 /*---
      6 es5id: 10.1.2_a
      7 description: Tests that Intl.Collator can be subclassed.
      8 author: Norbert Lindenberg
      9 includes: [compareArray.js]
     10 ---*/
     11 
     12 // get a collator and have it sort an array for comparison with the subclass
     13 var locales = ["tlh", "id", "en"];
     14 var a = ["A", "C", "E", "B", "D", "F"];
     15 var referenceCollator = new Intl.Collator(locales);
     16 var referenceSorted = a.slice().sort(referenceCollator.compare);
     17 
     18 class MyCollator extends Intl.Collator {
     19  constructor(locales, options) {
     20    super(locales, options);
     21    // could initialize MyCollator properties
     22  }
     23  // could add methods to MyCollator.prototype
     24 }
     25 
     26 var collator = new MyCollator(locales);
     27 a.sort(collator.compare);
     28 assert.compareArray(a, referenceSorted);
     29 
     30 reportCompare(0, 0);