Exhibit A:
var pt = [0,0,0,0,0,0];
console.log(pt[0], pt);
sometimes the log will spit out 0 [Infinity, Infinity, Infinity, Infinity, Infinity, Infinity], but only when you do a SIX zeroes array for pt. If you do five zeroes then you get an array of five zeroes as expected. The big clencher is how pt[0] can occassionally be 0 and Infinity a the same time confusion
Steps to re-create the problem:
- Download the
Developmentbranch of Flanvas - Make sure you place the folder in web-server directory (otherwise you will encounter cross-domain issues)
- Run the page
examples/loader-svg.js - Look at the console to see the mix-up I’m referring to.
*Notes
- The console log in question (Exhibit A) located in
src/flanvas.json line 2958 - The framework has recently undergone a "shload" of updates and you’ll notice not everything works — I am aware.
- I’m testing on
Mac OSX 10.6.8andChrome 15.0.874.121
If there are any problems with my instructions, please post back and I’ll get to them ASAP. Thanks.
** Clarification of the question **
If I run console.log(pt[0], pt); then I expect that the first value from the array pt and pt[0] will be identical. That’s not the case in my Exhibit A. Why not?
console.log()isn’t necessarily synchronous, so whatever code is causing the values to beInfinityis likely happening later.If you want to see the Array values in their current state, you need to be sure to capture its current value somehow.
One way is to abuse JSON for this purpose.
Or since it’s an Array of primitives, you could
sliceit.To find the actual issue, you’re going to have to follow
ptalong and see who’s misusing it.demonstration
Here’s a demo for illustrative purposes.
http://jsfiddle.net/J7tbB/
Note that this freezes your browser for
1000ms.As you can see, it creates an Array with 5 members initialized at
0, then immediately passes the Array toconsole.log.Right after that you have a
whileloop that will run for1000ms, incrementing each member once for each iteration.If the
console.logwas synchronous, you’d get your zeros. Instead you’ll likely get something like:Now if we change it so that it logs a
.slice()of the Array, you’ll see that you get your expected values.http://jsfiddle.net/J7tbB/1/