-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
prevent return "undefined" immediately when key is "constructor" for memoize method #998
Conversation
😮 Can you add a test case for this? |
Another way to fix this would be to do:
It'll still fail with |
aearly, it is my first "pull request", and sorry for that I am not very clear with the process, and I have added two test cases for it, and these two test cases can pass but it turn out another CI issue cannot pass "Node.js 5" of "retry as an embedded task with interval", saying "Assertion Message: The duration should have been greater than 400, but was 399". Actually I didn't change that test case, would you kindly help to give some hint for me to fix or any other advice? thanks a lot! |
The one possible issue is when @dacoozheng looks good for the most part, just some indentation issues. |
@megawac I refine it to allow "hasOwnProperty" as key. |
}, | ||
|
||
'avoid constructor key return undefined': function (test) { | ||
test.expect(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just fix this indentation and it looks fine
I prefer |
Problem is that async ~1.0 is es3 compatible. We could do create in v2
|
@qsona yes, if we just need a plain hash (Say, like a map), Object.create(null) should be a better way in ~ES5. var memo = Object.create(null) means create a plain object and not inherit from Object.prototype, so there are no attributes and methods from Object.prototype, Say, "toString/toLocalString", "hasOwnProperty", "constructor", "isPrototypeOf", "valueOf", ...etc. And solution is always responding to the requirement and situation, imagine below case: I am just thinking, return a normal javascript object maybe more better except document it explicitly in API document (Saying, the "memo" attribute is an Object.create(null)). |
@megawac I completely forgot that Thanks for pointing them out. I lacked the consideration. I also checked the |
I think, |
prevent return "undefined" immediately when key is "constructor" for memoize method
when key is "constructor", method after memoized will return "undefined" immediately.