The most bulletproof way of checking if an object has a certain key is:
Object.prototype.hasOwnProperty.call(obj, key)
This provides certain guarantees: it will only evaluate to true if key is a direct property of obj, and it will work even if obj doesn't have the usual Object as its prototype (for example, if it was created with const obj = Object.create(null)).
But it's a mouthful.
Is there any new syntax/method in ES6 or higher (including polyfillable or Babel-compilable 'proposals') that gives the same guarantees, but in a nicer, more readable way?
const iHaz = Object.prototype.hasOwnPropertythen use it likeconst iDoHaz = iHaz.call(obj, key)const has = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)is the alias I typically use.obj::Object.prototype.hasOwnProperty(key).obj::({}).hasOwnProperty(key)but that's a lose in terms of readability and I'm not sure how the precedence works out or even if the precedence for the bind operator proposal has stabilized.