Home > Article > Web Front-end > Two ways to determine whether a JS object has a certain attribute_javascript skills
Two ways, but slightly different
1, in operator
You can see that both name and toString on the prototype chain can be detected and return true.
2, hasOwnProperty method
The properties inherited on the prototype chain cannot be detected by hasOwnProperty and return false.
It should be noted that although in can detect the properties of the prototype chain, for in usually cannot.
Of course, after rewriting the prototype, for in is visible under IE9/Firefox/Safari/Chrome/Opera. See: Defects of for in