Bacon.fromArray is broken in node
werelax opened this issue · comments
Using node 6.3.1
and Bacon 0.7.84
:
> var Bacon = require('baconjs')
undefined
> Bacon.fromArray([1, 2, 3])
Error: not an array : 1,2,3
at assertArray (./node_modules/baconjs/dist/Bacon.js:54:11)
at Object.Bacon.fromArray (./node_modules/baconjs/dist/Bacon.js:2855:3)
at repl:1:7
at sigintHandlersWrap (vm.js:32:31)
at sigintHandlersWrap (vm.js:96:12)
at ContextifyScript.Script.runInContext (vm.js:31:12)
at REPLServer.defaultEval (repl.js:308:29)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:477:10)
assertArray
is failing because somehow this:
var isArray = function (xs) {
return xs instanceof Array;
};
is returning false
for [1, 2, 3]
😓
Isn't that a problem of Node?
It's not always simple in Javascript. Array.isArray(xs)
or Object.prototype.toString.call(xs) === '[object Array]';
(for older browsers) are workarounds for this.
I have confirmed that Bacon.fromArray indeed is "broken" with Node 6. I merged the PR and added a little optimization. Released 0.7.85.
It's funny that all tests pass with Node 6 and Bacon 0.7.84. Didn't dig into the details to find the reason for this.