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

Method class enumerable #15038

Closed
sant123 opened this issue Apr 5, 2017 · 6 comments
Closed

Method class enumerable #15038

sant123 opened this issue Apr 5, 2017 · 6 comments
Labels
Bug A bug in TypeScript ES6 Relates to the ES6 Spec Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it
Milestone

Comments

@sant123
Copy link

sant123 commented Apr 5, 2017

TypeScript Version: 2.2.2

Code

class Person {
    greet() { }
    bye() { }
}

function checkProperties(obj) {
    console.log("Keys found in (for-in):");
    for (let key in obj) {
        console.log(`Found key: ${key}`);
    }
}

let p = new Person();

checkProperties(p);

Expected behavior:
ES5 or ES6 target, the methods should be non-enumerable.

Actual behavior:
In ES5 the methods are enumerable.

@jwbay
Copy link
Contributor

jwbay commented Apr 5, 2017

Duplicate of #782? Also see #9769

@sant123
Copy link
Author

sant123 commented Apr 5, 2017

None of them @jwbay, properties should be enumerable according with ES6 Classes. Using Object.keys() or for-in loop shows the properties. However, this is not the case for methods.

@jwbay
Copy link
Contributor

jwbay commented Apr 5, 2017

When dealing with ES5 class constructs, methods are just prototype 'properties' that happen to be functions.

@sant123
Copy link
Author

sant123 commented Apr 5, 2017

Exactly but not in ES6, and the transpile from ES6 to ES5 should be equal right? I mean, if I change my target from ES5 to ES6 and in a part of my code I was using Object.keys() or for-in loop for getting name methods; the code will not work.

@MadaraUchiha
Copy link

MadaraUchiha commented Mar 6, 2018

As mentioned in #22354, also applies to static methods. Still occurs in 2.7.0.

@RyanCavanaugh
Copy link
Member

The impact of this is pretty small in practice and ES5 runtimes are getting pretty rare. We don't intend to address this given the other churn it would necessitate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript ES6 Relates to the ES6 Spec Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it
Projects
None yet
Development

No branches or pull requests

5 participants