Merge pull request #21 from seth-visere/master

Backbone.js getter and setter methods
This commit is contained in:
Jono Brandel 2011-06-18 11:05:23 -07:00
commit 8f8d7f8fdc
3 changed files with 13 additions and 4 deletions

View File

@ -134,12 +134,12 @@
<ul> <ul>
<li> <li>
<a href='https://github.com/dataarts/dat.gui/raw/build/DAT.GUI.min.js'><strong>Download the minified source</strong></a> <a href='https://github.com/dataarts/dat.gui/raw/build/DAT.GUI.min.js'><strong>Download the minified source</strong></a>
<small id='buildsizemin'>[19.5kb] <small id='buildsizemin'>[19.6kb]
</small> </small>
</li> </li>
<li> <li>
<a href='https://github.com/dataarts/dat.gui/raw/build/DAT.GUI.js'><strong>Download the uncompressed source</strong></a> <a href='https://github.com/dataarts/dat.gui/raw/build/DAT.GUI.js'><strong>Download the uncompressed source</strong></a>
<small id='buildsize'>[33.6kb] <small id='buildsize'>[33.8kb]
</small> </small>
</li> </li>

View File

@ -42,7 +42,13 @@ DAT.GUI.Controller.prototype.unlisten = function() {
}; };
DAT.GUI.Controller.prototype.setValue = function(n) { DAT.GUI.Controller.prototype.setValue = function(n) {
if(this.object[this.propertyName] != undefined){
this.object[this.propertyName] = n; this.object[this.propertyName] = n;
}else{
var o = new Object();
o[this.propertyName] = n;
this.object.set(o);
}
if (this.changeFunction != null) { if (this.changeFunction != null) {
this.changeFunction.call(this, n); this.changeFunction.call(this, n);
} }
@ -51,7 +57,9 @@ DAT.GUI.Controller.prototype.setValue = function(n) {
}; };
DAT.GUI.Controller.prototype.getValue = function() { DAT.GUI.Controller.prototype.getValue = function() {
return this.object[this.propertyName]; var val = this.object[this.propertyName];
if(val == undefined) this.object.get(this.propertyName);
return val;
}; };
DAT.GUI.Controller.prototype.updateDisplay = function() { DAT.GUI.Controller.prototype.updateDisplay = function() {

View File

@ -307,6 +307,7 @@ DAT.GUI = function(parameters) {
} }
var value = object[propertyName]; var value = object[propertyName];
if(value == undefined && object.get) value = object.get(propertyName));
// Does this value exist? Is it accessible? // Does this value exist? Is it accessible?
if (value == undefined) { if (value == undefined) {