Suggestion: "Object.hasOwnProperty"

doodad-js Admin doodadjs at gmail.com
Thu May 26 20:38:49 UTC 2016


>> Both the concern of `someObj.hasOwnProperty(somePropertyName)` attempting to call the `hasOwnProperty` property of `someObj` rather than walking the prototype chain to get `Object.prototype.hasOwnProperty`, and the >> concern of `someObj` having a null prototype (or otherwise not having `Object.prototype.hasOwnProperty` on its prototype chain) can be avoided with the `{}.hasOwnProperty.call(someObj, somePropertyName)` pattern.

Hi,

Yeah, sure. But it could be cleaner to do:

```js
Object.hasOwnProperty(myObj, someName)
```

instead of

```js
{}.hasOwnProperty.call(myObj, someName)
```




More information about the es-discuss mailing list