Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

Objects without prototype chain are broken #20

Closed
martinhoefling opened this issue Jan 5, 2016 · 4 comments
Closed

Objects without prototype chain are broken #20

martinhoefling opened this issue Jan 5, 2016 · 4 comments

Comments

@martinhoefling
Copy link
Contributor

When objects are created via Object.create(null) they cannot be expanded and the object properties are not shown due to Uncaught TypeError: obj.hasOwnProperty is not a function.
The problematic part is in https://github.com/chibicode/react-json-tree/blob/master/src/JSONObjectNode.js#L32 where it is assumed that hasOwnProperty is always present.

@skleeschulte
Copy link

Did you test your solution? I don't think it will work, because obj is not defined. The obj in the error message probably originates from the transpiled code. A solution could look like this:

if (Object.getPrototypeOf(data) === null || data.hasOwnProperty(key)) {

Unfortunately I cannot build the package myself, thus I cannot test changes and I don't want to make a PR.

@martinhoefling
Copy link
Contributor Author

Yes, so I changed that line and got the expected behavior (in my case). Edit: actually - I did not copy the line but instead made an edit on github. You're right - obj is not defined. Your suggestion seems to be the proper fix I guess.

@martinhoefling
Copy link
Contributor Author

I've pushed #23 and tested this. Works for me.

@chibicode
Copy link
Contributor

Closed #23 thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants