9/7 11:14:09p Node 1 !javascript c:\sbbs\xtrn\solar\alco-solar.js line 275: typeError: sfi.trim is not a function
So, my first question is, is the trim() function valid in JavaScript 1.8.5? I'm guessing it is because it's been working in
What I find interesting is that the error flagged on a trim() on line 275, but was OK with the trim() on line 270: timestamp.trim().
So, my first question is, is the trim() function valid in JavaScript
1.8.5? I'm guessing it is because it's been working in
Yes, it's a valid method on a String object.
What I find interesting is that the error flagged on a trim() on line
275, but was OK with the trim() on line 270: timestamp.trim().
In this case 'timestamp' is really just another String, since you're just grabbing the text from the feed and not turning it into a Number or Date object, so that makes sense.
My best guess is that the 'solarflux' value was absent when this person fetched the feed, or that they failed to fetch the feed altogether. On line 80, if 'solardata.solarflux' is undefined, 'sfi' gets set to 0, a Number, which does not have the '.trim()' method. Wrap that 0 in quotes on line 80 and this particular problem should go away.
Also, if you wanted to, you could also shorten things a bit by doing something like:
var sfi = solardata.solarflux || '0';
var sfi_int = parseInt(sfi);
var ai = solardata.aindex || 'No Data';
// etc.
That would be like a shorter version of:
var sfi = (typeof solardata.solarflux == 'undefined' ? '0' : solardata.solarflux);
Which is a shorter version of:
var sfi = solardata.solarflux;
if (sfi == undefined) {
var sfi = '0';
}
Sysop: | Chris Crash |
---|---|
Location: | Huntington Beach, CA. |
Users: | 578 |
Nodes: | 8 (0 / 8) |
Uptime: | 28:50:01 |
Calls: | 10,736 |
Calls today: | 1 |
Files: | 5 |
Messages: | 443,184 |
Posted today: | 1 |