prevent return "undefined" immediately when key is "constructor" for memoize method#998
prevent return "undefined" immediately when key is "constructor" for memoize method#998aearly merged 3 commits intocaolan:masterfrom
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. |
There was a problem hiding this comment.
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.