Change isPlainObject to support objects created in a different context#3068
Merged
quantizor merged 2 commits intostyled-components:masterfrom Apr 7, 2020
Merged
Conversation
kitten
reviewed
Mar 19, 2020
| export default (x: any): boolean => | ||
| x !== null && | ||
| typeof x === 'object' && | ||
| x.toString() === '[object Object]' && |
Member
There was a problem hiding this comment.
Like indicated in the PR, this will need to be Object.prototype.toString to support objects with toStrung, including Object.create(null) 🙌
Contributor
Author
There was a problem hiding this comment.
Ah yes of course, we can't call toString()if it doesn't exist on that object.
The problem I was trying to address by using x.toString() instead of Object.prototype.toString.call(x) was to call a custom toString when it exists:
class MyClass {
toString() {
return "[object MyClass]"
}
}
const m = new MyClass();
Object.prototype.toString.call(m); // "[object Object]" <-- does not call the custom toString method
m.toString(); // "[object MyClass]"I can solve this by using: (x.toString ? x.toString() : Object.prototype.toString.call(x)) === '[object Object]'
Contributor
Author
|
Hi @kitten, are you happy with this now that it has been updated? |
|
Looking forward to seeing this in action! 👏 |
This was referenced Apr 9, 2020
Merged
Merged
[Snyk] Upgrade styled-components from 5.0.1 to 5.1.0
FDMediagroep/fd-ts-react-breaking-news-alert#47
Merged
Merged
Merged
Merged
Merged
Merged
Merged
This was referenced Apr 30, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To resolve #3066