|
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 * @description Tests that Intl.Collator can be subclassed. |
|
7 * @author Norbert Lindenberg |
|
8 */ |
|
9 |
|
10 $INCLUDE("testIntl.js"); |
|
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 function MyCollator(locales, options) { |
|
19 Intl.Collator.call(this, locales, options); |
|
20 // could initialize MyCollator properties |
|
21 } |
|
22 |
|
23 MyCollator.prototype = Object.create(Intl.Collator.prototype); |
|
24 MyCollator.prototype.constructor = MyCollator; |
|
25 // could add methods to MyCollator.prototype |
|
26 |
|
27 var collator = new MyCollator(locales); |
|
28 a.sort(collator.compare); |
|
29 testArraysAreSame(referenceSorted, a); |
|
30 |