I'm trying to implement the Intl APIs in WebKit. I had the constructors mostly complete when I saw the new edition of the spec. I'd like to make sure I understand the implications of the changes, since the terminology is updated to match the ES 2015 spec, and not all of the concepts therein are concrete in WebKit's codebase yet.
In the 1.0 spec, calling a constructor with an existing object would initialize the object as a Collator (or NumberFormat or DateFormat) rather than creating a new object.
var obj = {}
Intl.Collator.call(obj) // returns obj
2.0 specifies the following:
1. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget.
2. Let collator be OrdinaryCreateFromConstructor(newTarget, %CollatorPrototype%).
3. ReturnIfAbrupt(collator).
4. Return InitializeCollator(collator, locales, options).
If I'm understanding correctly, that means that a new object is always created, and that new object's prototype is newTarget.prototype ||
%CollatorPrototype%. So when a class that extends Collator calls super() in the constructor, the new object is constructed with that class's prototype.
let obj = {}
Intl.Collator.call(obj) // no newTarget, so equivalent to new Intl.Collator()
class Collator2 extends Intl.Collator {
constructor (locale, options) {
super(locale, options)
this.extra = 'foo'
}
}
Collator2.prototype instanceof Intl.Collator ?
new Collator2() instanceof Intl.Collator // true
new Collator2().compare() // 0
Does that sound right?