Skip to content

Support ES5-style inheritance with Object.create (Salsa) #18609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
PhaserEditor2D opened this issue Sep 20, 2017 · 6 comments
Closed

Support ES5-style inheritance with Object.create (Salsa) #18609

PhaserEditor2D opened this issue Sep 20, 2017 · 6 comments
Labels
Domain: JavaScript The issue relates to JavaScript specifically In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@PhaserEditor2D
Copy link

TypeScript Version: 2.4.1

Salsa engine does not understand ES3 prototype inheritance.

Code

function A() {
    
}

A.prototype.hello = function (){
};

function B() {
    A.call(this);
}

B.prototype = Object.create(A.prototype);
B.prototype.constructor = B;

var b = new B();
b.[request completions]

Expected behavior:

It should show the list of methods inherited from A, like hello().

Actual behavior:

It does not show the methods from A.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Sep 21, 2017

ES3
Object.create

Hmmm. 😄

@DanielRosenwasser DanielRosenwasser changed the title ES3 prototype inheritance (Salsa) Support ES5-style inheritance with Object.create (Salsa) Sep 21, 2017
@DanielRosenwasser DanielRosenwasser added In Discussion Not yet reached consensus Suggestion An idea for TypeScript Salsa labels Sep 21, 2017
@DanielRosenwasser
Copy link
Member

As a matter of fact, we don't support the @class or @extends annotations either.

@PhaserEditor2D
Copy link
Author

The support of @class and @extends could be a simpler solution and a workaround instead of "recognize" the Object.create pattern.

@weswigham weswigham added Domain: JavaScript The issue relates to JavaScript specifically and removed Domain: JavaScript The issue relates to JavaScript specifically Salsa labels Nov 29, 2018
@andi23rosca
Copy link

andi23rosca commented Aug 14, 2019

Ran into this issue recently. Any updates?

Might try to make a pull request myself if anyone can point me in the right direction in the code.

@sandersn
Copy link
Member

There are two pieces to this:

  1. Recognising the pattern. You can look at the binder code like bindObjectDefinePropertyAssignment for an example. It's probably similar.
  2. Making constructor functions inherit from other constructor functions, or classes. Constructor functions don't create real class types right now, so there's no way to have them inherit from classes. It's possible to make an ad-hoc fix, or wait on something like my change on the constructor-functions-as-classes branch.

Instead implementing @extends support would make (1) easy but (2) would be the same.

@RyanCavanaugh
Copy link
Member

This doesn't seem common enough in modern JS to bother adding support for at this point.

@RyanCavanaugh RyanCavanaugh closed this as not planned Won't fix, can't repro, duplicate, stale Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: JavaScript The issue relates to JavaScript specifically In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants