-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
fix isPlainObject #306
fix isPlainObject #306
Conversation
…s instead of prototypes (did not work from iframes because Object in iframe is not the same as in parent)
Can you add a test that would have been failing with the previous version? |
I will try but don't know how to reproduce it inside the same context. |
Look into lodash tests? :-P |
Cc @jdalton |
It seems that lodash is creating its own context. |
OK I can reproduce it but had to install contextify for it. Can I push it with contextify as devDependency? |
Yes, sure. |
…e plain object from another realm is checked
return false; | ||
} | ||
|
||
return typeof obj === 'object' && | ||
Object.getPrototypeOf(obj) === Object.prototype; | ||
const proto = typeof obj.constructor === 'function' ? Object.getPrototypeOf(obj) : Object.prototype; |
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.
Please change const
to var
, we're maintaining Flow-friendliness for now. (I'll alter ESLint rule later.)
Looks good, thank you! |
Thank you for this awesome lib. :) |
FWIW lodash v4 drops IE8 support and has revised its It looks like this PR borrows from our WIP v4 implementation so you'll dig this method is designed to work with the es5-sham fallback for |
@jdalton Yes it is, I was pointed to look at the lodash implementation. I hope it's OK with you. |
@jdalton Appreciate you chiming in! |
In the long term copy pasting is a bummer as it shifts the implementation and testing burden to you all. It also means you all have to spend time mucking with and becoming experts in utils instead of making cool stuff on top of them. It's on me to make the existing lodash utils more consumer friendly and file size is part of that. I hope this can be revisited in v4 where file size is a major focal point. |
I agree totally. In our case we wanted to get some micro file size optimizations because the whole lib is 2KB minified+gzipped so we kind of sacrifice util maintainability. OTOH we only need three tiny utils so in my book it's worth the effort. |
When isPlainObject is called between two different contexts then Object.prototype is not the same. Now it is comparing only stringified constructors. Fixes #304