javascript - Observing changes to DOM properties -
i know when properties of arbitrary object change.
i read answer question: "extend setter default object" seemed suggest solution using getters , setters. however, tried use trap changes both id , style properties of dom object , did not work. 1 strange thing observed create setter id field original id field vanishes, attempts read or write value fails. property may dom property, aren't simple variables, can't create own variable can't arbitrarily re-create whatever underlying functionality generating value.
all want detect when property changes, , pass change through transparently.
some further research led me page presenting polyfill object.watch. however, while watch function appears let me see when properties of object change, actual properties wind not being changed @ all.
you can use mutation observers watch changes in attributes. works dom properties get/set markup attributes. compared mutation events, mutation observers run long after actual mutation, instead of immediately. i've read mutation observers perform better mutation events.
you bring question of how access original getter/setter when redefine property. won't need worry if use mutation observer solution. in browsers, such firefox, original functionality of property id implemented getter/setter. example, if ran object.getownpropertydescriptor(element.prototype, 'id').set.call(myelement, 'asdf'), myelement.id = 'asdf', if myelement.id redefined. browsers don't way. chromium, example, still working on implementing this aspect of web idl.
Comments
Post a Comment