summaryrefslogtreecommitdiff
path: root/lib/dojo/Stateful.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dojo/Stateful.js')
-rw-r--r--lib/dojo/Stateful.js35
1 files changed, 21 insertions, 14 deletions
diff --git a/lib/dojo/Stateful.js b/lib/dojo/Stateful.js
index e4f406309..147001962 100644
--- a/lib/dojo/Stateful.js
+++ b/lib/dojo/Stateful.js
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
+ Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
Available via Academic Free License >= 2.1 OR the modified BSD license.
see: http://dojotoolkit.org/license for details
*/
@@ -9,6 +9,7 @@ if(!dojo._hasResource["dojo.Stateful"]){ //_hasResource checks added by build. D
dojo._hasResource["dojo.Stateful"] = true;
dojo.provide("dojo.Stateful");
+
dojo.declare("dojo.Stateful", null, {
// summary:
// Base class for objects that provide named properties with optional getter/setter
@@ -33,7 +34,7 @@ dojo.declare("dojo.Stateful", null, {
// description:
// Get a named property on a Stateful object. The property may
// potentially be retrieved via a getter method in subclasses. In the base class
- // this just retrieves the object's property.
+ // this just retrieves the object's property.
// For example:
// | stateful = new dojo.Stateful({foo: 3});
// | stateful.get("foo") // returns 3
@@ -45,11 +46,11 @@ dojo.declare("dojo.Stateful", null, {
// summary:
// Set a property on a Stateful instance
// name:
- // The property to set.
+ // The property to set.
// value:
// The value to set in the property.
// description:
- // Sets named properties on a stateful object and notifies any watchers of
+ // Sets named properties on a stateful object and notifies any watchers of
// the property. A programmatic setter may be defined in subclasses.
// For example:
// | stateful = new dojo.Stateful();
@@ -66,7 +67,7 @@ dojo.declare("dojo.Stateful", null, {
// This is equivalent to calling set(foo, "Howdy") and set(bar, 3)
if(typeof name === "object"){
for(var x in name){
- this.set(x, name[x]);
+ this.set(x, name[x]);
}
return this;
}
@@ -81,17 +82,17 @@ dojo.declare("dojo.Stateful", null, {
// summary:
// Watches a property for changes
// name:
- // Indicates the property to watch. This is optional (the callback may be the
+ // Indicates the property to watch. This is optional (the callback may be the
// only parameter), and if omitted, all the properties will be watched
// returns:
- // An object handle for the watch. The unwatch method of this object
+ // An object handle for the watch. The unwatch method of this object
// can be used to discontinue watching this property:
// | var watchHandle = obj.watch("foo", callback);
// | watchHandle.unwatch(); // callback won't be called now
// callback:
// The function to execute when the property changes. This will be called after
// the property has been changed. The callback will be called with the |this|
- // set to the instance, the first argument as the name of the property, the
+ // set to the instance, the first argument as the name of the property, the
// second argument as the old value and the third argument as the new value.
var callbacks = this._watchCallbacks;
@@ -99,15 +100,18 @@ dojo.declare("dojo.Stateful", null, {
var self = this;
callbacks = this._watchCallbacks = function(name, oldValue, value, ignoreCatchall){
var notify = function(propertyCallbacks){
- for(var i = 0, l = propertyCallbacks && propertyCallbacks.length; i < l; i++){
- try{
- propertyCallbacks[i].call(self, name, oldValue, value);
- }catch(e){
- console.error(e);
+ if(propertyCallbacks){
+ propertyCallbacks = propertyCallbacks.slice();
+ for(var i = 0, l = propertyCallbacks.length; i < l; i++){
+ try{
+ propertyCallbacks[i].call(self, name, oldValue, value);
+ }catch(e){
+ console.error(e);
+ }
}
}
};
- notify(callbacks[name]);
+ notify(callbacks['_' + name]);
if(!ignoreCatchall){
notify(callbacks["*"]); // the catch-all
}
@@ -116,6 +120,9 @@ dojo.declare("dojo.Stateful", null, {
if(!callback && typeof name === "function"){
callback = name;
name = "*";
+ }else{
+ // prepend with dash to prevent name conflicts with function (like "name" property)
+ name = '_' + name;
}
var propertyCallbacks = callbacks[name];
if(typeof propertyCallbacks !== "object"){