Show
Ignore:
Timestamp:
08/05/08 12:12:24 (6 years ago)
Author:
os0x
Message:
  • binding
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/watch/watch.js

    r17065 r17091  
    55    var getter = this.__lookupGetter__(prop), 
    66      setter = this.__lookupSetter__(prop), 
    7       oldval = this[prop]; 
     7      oldval = this[prop], 
     8      self = this; 
    89    if (!(prop in watched)) { 
    910      watched[prop] = { 
    1011        setter: setter, 
    1112        getter: getter, 
     13        self:self 
    1214      }; 
    1315    } 
    1416    this.__defineSetter__(prop, 
    1517      function(newval) { 
    16         var setter = watched[prop].setter; 
    17         return oldval = setter? 
    18           setter(handler(prop, oldval, newval)): 
     18        var setter = watched[prop].setter, 
     19        self = watched[prop].self; 
     20        return typeof setter == "function" ? 
     21          setter.call(self,handler(prop, oldval, newval)) : 
    1922          handler(prop, oldval, newval); 
    2023      }); 
    2124    this.__defineGetter__(prop, 
    2225      function() { 
    23         var getter = watched[prop].getter; 
    24         return getter? getter(): oldval; 
     26        var getter = watched[prop].getter, 
     27        self = watched[prop].self; 
     28        return typeof getter == "function" ? getter.call(self): oldval; 
    2529      }); 
    2630  } 
    2731  Object.prototype.unwatch = function(prop, handler) { 
    28     var setter, 
    29       getter; 
     32    var setter, getter; 
    3033    if (!(prop in watched)) return; 
    3134    delete this[prop];