hasownproperty

Javascript what is property in hasOwnProperty?

安稳与你 提交于 2019-11-27 06:43:26
if (someVar.hasOwnProperty('someProperty') ) { // do something(); } else { // do somethingElse(); } What is the right use/explanation of hasOwnProperty('someProperty') ? Why we can't simply use someVar.someProperty to check if an object someVar contains property with name someProperty ? What is a property in this case? What property does this javascript check? hasOwnProperty returns a boolean value indicating whether the object on which you are calling it has a property with the name of the argument. For example: var x = { y: 10 }; console.log(x.hasOwnProperty("y")); //true console.log(x

object has no hasOwnProperty method (i.e. it's undefined) - IE8

我与影子孤独终老i 提交于 2019-11-27 04:36:25
This seems quite bizarre. Here's my experiment in the IE8 console: typeof obj1 // "object" obj1.hasOwnProperty // {...} typeof obj2 // "object" obj2.hasOwnProperty // undefined Any ideas as to what could cause this? This example is from IE8, but the same return is from IE6+ and most other IE browsers. IE before #9 does not define it for host objects var o=window;// or document or document elements o.hasOwnProperty /* returned value: (undefined) undefined */ 来源: https://stackoverflow.com/questions/8157700/object-has-no-hasownproperty-method-i-e-its-undefined-ie8