javascript - Object.freeze doesn't really freeze -
mdn claims executing .freeze
on object:
nothing can added or removed properties set of frozen object.
now take @ example:
var span = document.createelement("span"); span.id = "foo"; console.log(span.id); //foo object.freeze(span); span.setattribute("id", "bar"); console.log(span.id); //bar
the id
property changed when object frozen. through span.hasownproperty("id")
know id
indeed local property of span
.
the whole dom object in javascript should prevent id
beingness changed. not doing thing. why?
the reason why .id
still beingness changed, because not beingness changed. looks has changed. .id
defined setter , getter, grabs corresponding attribute value upon called. if preset setter , getter manually removed, value not alter expected:
var span = document.createelement("span"); delete span.id; //remove setter , getter span.id = "foo"; console.log(span.id); //foo object.freeze(span); span.setattribute("id", "bar"); console.log(span.id); //foo
the actual dom separate accessible object in js, getattribute("id")
still homecoming "bar"
.
javascript dom
No comments:
Post a Comment