I had an idea to store code as lists (arrays) in Node and execute them, but this is harder than I thought: if I make a list with a function in the beginning or in the end, .pop
or .shift
removes but omits it and returns the next element:
> l = [1, 75, 84, function() { console.log('aseuht') }]
[ 1, 75, 84, [Function] ]
> l.pop()
84
> l
[ 1, 75 ]
I noticed this in Node v0.4.9, but it is still present in 0.6.10.
Is there a workaround for that?
update: I filed an issue on GitHub.
update 2: the bug is present only in my shell, when I run these commands from a standalone script, it works correctly. So this is just a shell issue.
I just tried it in Node, Firefox, and Chrome and it worked as expected in all three.
here's the code I used:
var l= [1, 75, 84, function() { console.log('aseuht'); }];
console.log(l);
console.log(l.pop());
console.log(l);
and result:
[ 1, 75, 84, [Function] ]
[Function]
[ 1, 75, 84 ]
and the JSFiddle: http://jsfiddle.net/Q5M8M/
What version of Node are you using?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With