diff --git a/lib/connectors/memory.js b/lib/connectors/memory.js index 7af66e29..c974a0b9 100644 --- a/lib/connectors/memory.js +++ b/lib/connectors/memory.js @@ -117,7 +117,7 @@ Memory.prototype.fromDb = function(model, data) { if (!data) return null; data = JSON.parse(data); var props = this._models[model].properties; - Object.keys(data).forEach(function (key) { + for(var key in data) { var val = data[key]; if (typeof val === 'undefined' || val === null) { return; @@ -136,7 +136,7 @@ Memory.prototype.fromDb = function(model, data) { } } data[key] = val; - }); + } return data; }; diff --git a/lib/dao.js b/lib/dao.js index 9bee58a3..6d2675f9 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -58,14 +58,14 @@ DataAccessObject._forDB = function (data) { return data; } var res = {}; - Object.keys(data).forEach(function (propName) { + for(var propName in data) { var type = this.getPropertyType(propName); if (type === 'JSON' || type === 'Any' || type === 'Object' || data[propName] instanceof Array) { res[propName] = JSON.stringify(data[propName]); } else { res[propName] = data[propName]; } - }.bind(this)); + } return res; }; @@ -700,9 +700,9 @@ DataAccessObject.prototype.updateAttributes = function updateAttributes(data, cb } // update instance's properties - Object.keys(data).forEach(function (key) { + for(var key in data) { inst[key] = data[key]; - }); + } inst.isValid(function (valid) { if (!valid) { @@ -713,16 +713,16 @@ DataAccessObject.prototype.updateAttributes = function updateAttributes(data, cb inst.trigger('save', function (saveDone) { inst.trigger('update', function (done) { - Object.keys(data).forEach(function (key) { + for(var key in data) { inst[key] = data[key]; - }); + } inst._adapter().updateAttributes(model, getIdValue(inst.constructor, inst), inst.constructor._forDB(data), function (err) { if (!err) { // update $was attrs - Object.keys(data).forEach(function (key) { + for(var key in data) { inst.__dataWas[key] = inst.__data[key]; - }); + }; } done.call(inst, function () { saveDone.call(inst, function () { diff --git a/lib/model.js b/lib/model.js index 766f7d45..88a8ceb3 100644 --- a/lib/model.js +++ b/lib/model.js @@ -99,20 +99,20 @@ ModelBaseClass.prototype._initProperties = function (data, applySetters) { } if (applySetters === true) { - Object.keys(data).forEach(function (propertyName) { + for(var propertyName in data) { if((propertyName in properties) || (propertyName in ctor.relations)) { self[propertyName] = self.__data[propertyName] || data[propertyName]; } - }); + } } // Set the unknown properties as properties to the object if(strict === false) { - Object.keys(data).forEach(function (propertyName) { + for(var propertyName in data) { if(!(propertyName in properties)) { self[propertyName] = self.__data[propertyName] || data[propertyName]; } - }); + } } ctor.forEachProperty(function (propertyName) { @@ -224,7 +224,7 @@ ModelBaseClass.prototype.toObject = function (onlySchema) { }); if (schemaLess) { - Object.keys(self.__data).forEach(function (propertyName) { + for(var propertyName in self.__data) { if (!data.hasOwnProperty(propertyName)) { var val = self.hasOwnProperty(propertyName) ? self[propertyName] : self.__data[propertyName]; if(val !== undefined && val!== null && val.toObject) { @@ -233,7 +233,7 @@ ModelBaseClass.prototype.toObject = function (onlySchema) { data[propertyName] = val; } } - }); + } } return data; }; @@ -248,9 +248,9 @@ ModelBaseClass.prototype.toJSON = function () { }; ModelBaseClass.prototype.fromObject = function (obj) { - Object.keys(obj).forEach(function (key) { + for(var key in obj) { this[key] = obj[key]; - }.bind(this)); + } }; /** @@ -271,14 +271,14 @@ ModelBaseClass.prototype.propertyChanged = function propertyChanged(propertyName */ ModelBaseClass.prototype.reset = function () { var obj = this; - Object.keys(obj).forEach(function (k) { + for(var k in obj) { if (k !== 'id' && !obj.constructor.dataSource.definitions[obj.constructor.modelName].properties[k]) { delete obj[k]; } if (obj.propertyChanged(k)) { obj[k] = obj[k + '$was']; } - }); + } }; ModelBaseClass.prototype.inspect = function () {