| 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: 11.1.2 |
| 7 |
description: Tests that Intl.NumberFormat can be subclassed. |
| 8 |
author: Norbert Lindenberg |
| 9 |
includes: [compareArray.js] |
| 10 |
---*/ |
| 11 |
|
| 12 |
// get a number format and have it format an array of numbers for comparison with the subclass |
| 13 |
var locales = ["tlh", "id", "en"]; |
| 14 |
var a = [0, 1, -1, -123456.789, -Infinity, NaN]; |
| 15 |
var referenceNumberFormat = new Intl.NumberFormat(locales); |
| 16 |
var referenceFormatted = a.map(referenceNumberFormat.format); |
| 17 |
|
| 18 |
class MyNumberFormat extends Intl.NumberFormat { |
| 19 |
constructor(locales, options) { |
| 20 |
super(locales, options); |
| 21 |
// could initialize MyNumberFormat properties |
| 22 |
} |
| 23 |
// could add methods to MyNumberFormat.prototype |
| 24 |
} |
| 25 |
|
| 26 |
var format = new MyNumberFormat(locales); |
| 27 |
var actual = a.map(format.format); |
| 28 |
assert.compareArray(actual, referenceFormatted); |