Documented breaking change for subclassing built-ins.#100
Merged
DanielRosenwasser merged 2 commits intomasterfrom Dec 6, 2016
Merged
Documented breaking change for subclassing built-ins.#100DanielRosenwasser merged 2 commits intomasterfrom
DanielRosenwasser merged 2 commits intomasterfrom
Conversation
mhegazy
approved these changes
Dec 6, 2016
Breaking-Changes.md
Outdated
| you may find that: | ||
|
|
||
| * methods may be `undefined` on objects returned by constructing these subclasses, so calling `sayHello` will result in ane error. | ||
| * `instanceof` will be broken between instances of the subclass and their instances, so `(new FooError()) instanceof FooError` may return `false`. |
Breaking-Changes.md
Outdated
|
|
||
| As part of substituting the value of `this` with the value returned by a `super(...)` call, subclassing `Error`, `Array`, and others may no longer work as expected. | ||
| This is due to the fact that constructor functions for `Error`, `Array`, and the like use ES6's `new.target` to adjust the prototype chain; | ||
| however, there is no way to emulate the semantics of `new.target` in ECMAScript 5. |
Contributor
There was a problem hiding this comment.
it might be worth noting that it was not working correctelly in TS 2.0 either for the same reason.
There was a problem hiding this comment.
I disagree with the statement that "there is no way to emulate the semantics of new.target", we just haven't implemented it yet.
Example:
class C {
constructor() {
return Object.setPrototypeOf({}, new.target.prototype);
}
}
//
var C = (function () {
function C() {
var _newTarget = this && this instanceof C ? this.constructor : void 0;
return Object.setPrototypeOf({}, _newTarget.prototype);
}
return C;
})();
Member
Author
There was a problem hiding this comment.
I'll amend this so that we state that there is no way to ensure a value of new.target when invoking a constructor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@mhegazy @rbuckton