From da9ff6f4ae7d937d8c0a23a42ce70616e60bc718 Mon Sep 17 00:00:00 2001 From: Markus Stefanko Date: Thu, 8 Mar 2018 13:15:14 +0700 Subject: [PATCH] Move numericValue setter/getter to prototype --- index.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index 3477321..dcefb8f 100644 --- a/index.js +++ b/index.js @@ -652,21 +652,23 @@ function SpreadsheetCell(spreadsheet, ss_key, worksheet_id, data){ } }); + Object.defineProperty(SpreadsheetCell.prototype, "numericValue", { + get: function() { + return this._numericValue; + }, + set: function(val) { + if (val === undefined || val === null) return this._clearValue(); - self.__defineGetter__('numericValue', function() { - return self._numericValue; - }); - self.__defineSetter__('numericValue', function(val) { - if (val === undefined || val === null) return self._clearValue(); + if (isNaN(parseFloat(val)) || !isFinite(val)) { + throw new Error('Invalid numeric value assignment'); + } - if (isNaN(parseFloat(val)) || !isFinite(val)) { - throw new Error('Invalid numeric value assignment'); - } + this._value = val.toString(); + this._numericValue = parseFloat(val); + this._formula = undefined; + } + }); - self._value = val.toString(); - self._numericValue = parseFloat(val); - self._formula = undefined; - }); self.__defineGetter__('valueForSave', function() { return xmlSafeValue(self._formula || self._value);