When looping with an object, const
, let
keywords malfunction on Bixby capsule local-endpoint javascript.
I ran Bixby studio on my laptop(Ubuntu 18.04). Trying Bixby simulator, on debug console api result is constructed in an unexpected way.
var http = require('http')
var console = require('console')
var config = require('config')
module.exports.function = function getBTCRates () {
console.log("GET /ticker without any parameter!)")
// Read the remote.url value from capsule.properties
var response = http.getUrl(config.get('blockchain.url') + '/ticker', { format: 'json' });
var items = [];
for (var currency in response) {
var item = response[currency];
item.quarterBefore = item['15m']
delete item['15m'];
item.currency = currency;
items.push(item)
}
return items;
}
If I change var
keywords to const
or let
as follows, it malfunctions.
var http = require('http')
var console = require('console')
var config = require('config')
module.exports.function = function getBTCRates () {
console.log("GET /ticker without any parameter!)")
// Read the remote.url value from capsule.properties
var response = http.getUrl(config.get('blockchain.url') + '/ticker', { format: 'json' });
const items = [];
for (let currency in response) {
const item = response[currency];
item.quarterBefore = item['15m']
delete item['15m'];
item.currency = currency;
items.push(item)
}
return items;
}
When I use const
, let
keywords, result is as follows:
When I use var
keywords, result is as follows:
A few suggestions:
const
or let
to isolate the issue.