Skip to content

Commit

Permalink
Move value setter/getter to prototype
Browse files Browse the repository at this point in the history
  • Loading branch information
mastef committed Mar 8, 2018
1 parent 2a30fde commit d6d299e
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,33 +605,37 @@ function SpreadsheetCell(spreadsheet, ss_key, worksheet_id, data){
this.save(cb);
};

self.__defineGetter__('value', function(){
return self._value;
});
self.__defineSetter__('value', function(val){
if (!val) return self._clearValue();
SpreadsheetCell.prototype._clearValue = function() {
this._formula = undefined;
this._numericValue = undefined;
this._value = '';
}

var numeric_val = parseFloat(val);
if (!isNaN(numeric_val)){
self._numericValue = numeric_val;
self._value = val.toString();
} else {
self._numericValue = undefined;
self._value = val;
}
Object.defineProperty(SpreadsheetCell.prototype, "value", {
get: function(){
return this._value;
},
set: function(val){
if (!val) return this._clearValue();

var numeric_val = parseFloat(val);
if (!isNaN(numeric_val)){
this._numericValue = numeric_val;
this._value = val.toString();
} else {
this._numericValue = undefined;
this._value = val;
}

if (typeof val == 'string' && val.substr(0,1) === '=') {
// use the getter to clear the value
this.formula = val;
} else {
this._formula = undefined;
}
}
});

if (typeof val == 'string' && val.substr(0,1) === '=') {
// use the getter to clear the value
self.formula = val;
} else {
self._formula = undefined;
}
});

self.__defineGetter__('formula', function() {
return self._formula;
Expand Down

0 comments on commit d6d299e

Please sign in to comment.