Mozilla's website clearly describes hasOwnProperty()and in.
hasOwnProperty()
in
However, it does not provide any implementation details regarding their effectiveness.
I would suspect that they will O(1)(constant time), but would like to see any links or tests that may exist.
O(1)
To include my comments in the response.
hasOwnProperty()should be O(1), as this is a key search, but it will be implementation specific.
in, , ( , hasOwnProperty(), ), , . hasOwnProperty() for ( in ).
for ( in )
, . , :)
, in , hasOwnProperty(). in hasProperty() ( : http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf - . . 79), , ( ). , , in .
hasProperty()
: http://jsfiddle.net/VhhzR/2/
Firefox in . Chrome in ( ). Internet Explorer in .
, :)
I donβt think that this is any different from the mechanism for searching for properties of an object, since they act essentially the same thing, the difference hasOwnProperty(prop)only looks in the object itself, while it o.propwill go down the hierarchy of prototypes.
hasOwnProperty(prop)
o.prop