michael@0: // Copyright 2011-2012 Norbert Lindenberg. All rights reserved. michael@0: // Copyright 2012 Mozilla Corporation. All rights reserved. michael@0: // This code is governed by the BSD license found in the LICENSE file. michael@0: michael@0: /** michael@0: * @description Tests that Intl.NumberFormat can be subclassed. michael@0: * @author Norbert Lindenberg michael@0: */ michael@0: michael@0: $INCLUDE("testIntl.js"); michael@0: michael@0: // get a number format and have it format an array of numbers for comparison with the subclass michael@0: var locales = ["tlh", "id", "en"]; michael@0: var a = [0, 1, -1, -123456.789, -Infinity, NaN]; michael@0: var referenceNumberFormat = new Intl.NumberFormat(locales); michael@0: var referenceFormatted = a.map(referenceNumberFormat.format); michael@0: michael@0: function MyNumberFormat(locales, options) { michael@0: Intl.NumberFormat.call(this, locales, options); michael@0: // could initialize MyNumberFormat properties michael@0: } michael@0: michael@0: MyNumberFormat.prototype = Object.create(Intl.NumberFormat.prototype); michael@0: MyNumberFormat.prototype.constructor = MyNumberFormat; michael@0: // could add methods to MyNumberFormat.prototype michael@0: michael@0: var format = new MyNumberFormat(locales); michael@0: var actual = a.map(format.format); michael@0: testArraysAreSame(referenceFormatted, actual); michael@0: