Odd javascript behavior for checking "constructor" key in object -
i not sure if stumbled upon unwanted behavior in javascript or if somehow intended behavior.
the following code results in true statement:
var test= {"test":1} document.write("constructor" in test); http://jsfiddle.net/xyatxm2g/2/
if change following code, returns false should:
var test= {"test":1} document.write(test.hasownproperty("constructor"));
the hasownproperty method, name says, object see if has property itself.
but when use 'propertyname' in test, you're not looking object's own properties, properties come inheritance.
in case, constructor property resides inside object's prototype, objects have property, because inherit object.
quote mdn
every object descended object inherits hasownproperty method. method can used determine whether object has specified property direct property of object; unlike
inoperator, method not check down object's prototype chain.
Comments
Post a Comment