-
Notifications
You must be signed in to change notification settings - Fork 512
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
Refactor all those cycles with .hasOwnProperty #34
Comments
That is a good idea, I will give it a try. |
Interestingly, not calling hasOwnProperty at all is significantly faster in those cases where we control the prototype chain: http://jsperf.com/object-keysv-vs-object-hasownproperty/5 I also changed the test to use less properties which is a more common situation. |
It's brittle. And |
But the speedup is massive. |
As I said, in those cases where we totally control the prototype chain, not calling hasOwnProperty is a massive win, for any other situation I agree that using Object.keys seems like a better option. Sometimes we actually want the key or both the key and the value ( |
FYI, for..of gives you keys, values or both depending on which iterator you call it. But yes, it's not out there yet, ES6 is not yet finished. David Galeano wrote:
|
AFAIK, for a regular object (which is what I thought we were talking about) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of |
yes, yes, just, you can use David Galeano wrote:
|
It is the slowest way to get to enumerate own properties (http://jsperf.com/object-keysv-vs-object-hasownproperty/3).
If you argue with ECMAScript3 bacward compatibility, you aren't anyway (you use Object.defineProperty to define getters and setters in certain parts of the code), not to mention, it is hard to find non-ES5 browser nowadays...
The text was updated successfully, but these errors were encountered: