Skip to content
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

Need to extends static getters and setters. #4664

Closed
vilicvane opened this issue Sep 5, 2015 · 7 comments
Closed

Need to extends static getters and setters. #4664

vilicvane opened this issue Sep 5, 2015 · 7 comments
Labels
Canonical This issue contains a lengthy and complete description of a particular problem, solution, or design Duplicate An existing issue was already created Question An issue which isn't directly actionable in code

Comments

@vilicvane
Copy link
Contributor

Maybe something like this?

var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) Object.defineProperty(d, p, Object.getOwnPropertyDescriptor(b, p));
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};

Or is there a better polyfill around the corner?

@mhegazy
Copy link
Contributor

mhegazy commented Sep 5, 2015

looks right to me.

Also related to #2009

@mhegazy mhegazy added the Question An issue which isn't directly actionable in code label Sep 5, 2015
@mhegazy mhegazy closed this as completed Sep 5, 2015
@vilicvane
Copy link
Contributor Author

Consider this:

class A {
    static y;
    static get x() {
        return this.y;
    }
}

class B extends A { }

B.y = 123;
console.log(B.x);

The code emitted by TypeScript will log undefined, while Babel will handle it correctly.

@vilicvane
Copy link
Contributor Author

I guess you might expect us to define customized helper, but this could be a common usage I think.

@vilicvane vilicvane changed the title Need to extends static getter and setters. Need to extends static getters and setters. Dec 30, 2015
@vilicvane
Copy link
Contributor Author

@mhegazy Hi, this is still an issue. __extends should copy the property descriptor instead of the value directly. Currently the helper is doing:

d[p] = b[p];

But it should better do:

Object.defineProperty(d, p, Object.getOwnPropertyDescriptor(b, p));

@DanielRosenwasser
Copy link
Member

I think this has always been an issue, which is why users are free to use their own __extends. See @RyanCavanaugh's comment on #1520 (comment)

@DanielRosenwasser DanielRosenwasser added Duplicate An existing issue was already created and removed Question An issue which isn't directly actionable in code labels Dec 31, 2015
@DanielRosenwasser
Copy link
Member

Marking this as a duplicate of #1520.

@DanielRosenwasser DanielRosenwasser added the Question An issue which isn't directly actionable in code label Dec 31, 2015
@vilicvane
Copy link
Contributor Author

@DanielRosenwasser Thanks for the information!

@DanielRosenwasser DanielRosenwasser added the Canonical This issue contains a lengthy and complete description of a particular problem, solution, or design label Dec 31, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Canonical This issue contains a lengthy and complete description of a particular problem, solution, or design Duplicate An existing issue was already created Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants