I have the follow function:
Download.prototype.fundamentals = function(exchanges, cb){
if (!(exchange = exchanges.pop())) return
var that = this;
this.login(function(err){
if (err) return cb(true, exchange.code)
var path = util.format(that.eoddata.fundamentals['path'], that.token, exchange.code)
that.get(that.eoddata.fundamentals['host'], path, function(err, data){
if (err) return cb(true, exchange.code)
that.xml(data, function(err, data){
if (err || data['@'].Message != 'Success') return cb(true, exchange.code)
var stocks = data['FUNDAMENTALS']['FUNDAMENTAL']
that.insert(stocks, exchange, function(){
cb(false, exchange.code)
})
that.fundamentals(exchanges, cb)
})
})
})
}
I think it easy to understand, I pop()
an element to a list and then do other operations, and then recall the function to pop()
another element.
I have a doubt regarding the writing of the function, now it works, but it does not seem very optimized. Example: I do not like var that = this
.
How could I rewrite it better?