Javascript assignment operator is not working
-
18-06-2021 - |
Domanda
log.original_fields is always null. why?
var updateChangeLog = function(log, currentRecord) {
var records, record;
if(!log.original_fields) {
records = ["a","b"];
log["original_fields"] = records;
// log.original_fields = records; // doesnt work either
debugger;
}
}
Soluzione
I don't thin it's good practice to modify an object the function recieves as a param, at least without then returning the object. Better way would be make the function a method of the log object.
like logObject.updateChangeLog(currentRecord);
the updateChangeLog would containt ... if(!self.original_fields) self.original_fields = records; ... but remember to initialize the logObject original_fields to false or nil.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow