tor-browser

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

subclassing.js (1060B)


      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: 12.1.2
      7 description: Tests that Intl.DateTimeFormat can be subclassed.
      8 author: Norbert Lindenberg
      9 includes: [compareArray.js]
     10 ---*/
     11 
     12 // get a date-time format and have it format an array of dates for comparison with the subclass
     13 var locales = ["tlh", "id", "en"];
     14 var a = [new Date(0), Date.now(), new Date(Date.parse("1989-11-09T17:57:00Z"))];
     15 var referenceDateTimeFormat = new Intl.DateTimeFormat(locales);
     16 var referenceFormatted = a.map(referenceDateTimeFormat.format);
     17 
     18 class MyDateTimeFormat extends Intl.DateTimeFormat {
     19  constructor(locales, options) {
     20    super(locales, options);
     21    // could initialize MyDateTimeFormat properties
     22  }
     23  // could add methods to MyDateTimeFormat.prototype
     24 }
     25 
     26 var format = new MyDateTimeFormat(locales);
     27 var actual = a.map(format.format);
     28 assert.compareArray(actual, referenceFormatted);
     29 
     30 reportCompare(0, 0);