The `{{hash}}` helper creates objects that don't inherit from `Object.prototype`
sandydoo opened this issue · 1 comments
Description
The object created by the hash
helper does not inherit from Object.prototype
and is missing a lot of common functions like hasOwnProperty
.
I've been a bit out of the loop, but it seems the behaviour may have changed in: 52f5257
Reproduce
The issue can be reproduced in the production docs for ember-google-maps: https://ember-google-maps.sandydoo.me/docs/directions
Throughout the docs for ember-google-maps, I suggest that people use the hash
helper to quickly build up map settings without leaving the template. For example:
The above currently breaks Google Maps when it tries to call hasOwnProperty
on the polylineOptions
object.
Expected behaviour and feedback
Is this a reasonable use-case for the hash
helper? Or should I ditch the idea and remove this pattern from the documentation?
One could argue that creating the object outside of the template is the safer option, given how restrictive the hash helper is around updates. There's nothing stopping a third-party library like Google Maps from calling set
in the future and breaking the app.
It's also fair to argue that Google Maps should be using something like Object.prototype.hasOwnProperty.call
to be safe.
Any guidance, thoughts, and suggestions are very welcome!
I found out that this behavior is mentioned in the docs.
Note that the hash is an empty object with no prototype chain, therefore common methods like toString are not available in the resulting hash. If you need to use such a method, you can use the call or apply approach:
I guess the solution here is to introduce a custom hash helper.