unsetProperty()

One of the suggestions the Toshiba folks made to my comp 5 code was to,

"call unsetProperty() for each set to state.value in script to avoid global state side-effect"

So for instance:

document.FOO.state.unsetProrpety("value");
document.FOO.state.value = "true";

I read V17-104 but don't really understand the what unsetProperty does and why it is necessary before setting a propert.



Answer this question

unsetProperty()

  • Dave12349

    "State properties hold their value when unset, unlike style properties which when unset revert to the the current value from markup. So you don't necessarily want to be in the habit of unsetting style properties... just state ones."

    Ahhh, ok thanks Scott. Very helpful.


  • Biocide

    Scott, you almost have it correct -- only state:focused is global, since it is a "shared" resource. state:value is not global.

    Nevertheless the difference between normal behaviour and state behaviour is covered in my old post at http://blogs.msdn.com/ptorr/archive/2006/09/08/746678.aspx

    www.live.com will give that as the first hit if you search for "unsetProperty" :-)



  • Tdah

    Hey Will,

    You actually have the two lines reversed. You need to call unsetProperty immediately after you set any state value from script.

    Peter or someone from MS might be able to explain why the state machine works the way it does, but this is my understanding...

    when setting style values from script the style value for the node you are manipulating is locked from markup modifying it's value until you do the unsetProperty to release the scripts contorl of that property back to markup.

    the state engine is different however. When you set a state property, whether it is value, focused, or whatever, it locks the state property for ALL nodes from being modified outside of script. So the "state side-effect" is that if you set a state.value for one node but hten later in markup are setting the state.value for a different node... that later call in markup will not work even though it is on a different node.

    So the habit to get in, is no matter what, whenever you modifiy a state property regardless of what property it is, then you must unset it immediately.

    State properties hold their value when unset, unlike style properties which when unset revert to the the current value from markup. So you don't necessarily want to be in the habit of unsetting style properties... just state ones.

    _scottt


  • unsetProperty()