underscore-observe
underscore-observe copied to clipboard
using this in node console fails
Because of node repl's use of the _ variable.
$ node
> var _ = require('underscore')
undefined
> _.each
TypeError: Cannot read property 'each' of undefined
at repl:1:3
at REPLServer.self.eval (repl.js:109:21)
at Interface.<anonymous> (repl.js:248:12)
at Interface.EventEmitter.emit (events.js:96:17)
at Interface._onLine (readline.js:200:10)
at Interface._line (readline.js:518:8)
at Interface._ttyWrite (readline.js:736:14)
at ReadStream.onkeypress (readline.js:97:10)
at ReadStream.EventEmitter.emit (events.js:126:20)
at emitKey (readline.js:1058:12)
> require('./assets/js/lib/underscore.observable.js')
TypeError: Cannot call method 'mixin' of undefined
at c:\Users\jcollum\Dev\prevision8\web\assets\js\lib\underscore.observable.js:19
6:7
at Object.<anonymous> (c:\Users\jcollum\Dev\prevision8\web\assets\js\lib\undersc
ore.observable.js:246:3)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at repl:1:2
at REPLServer.self.eval (repl.js:109:21)
>
If I use var und = require('underscore')
it will be fine until I use the observe function:
> a
[ 'zero',
'one',
'two',
'trhee',
'fffour' ]
> und.observe(a, func)
TypeError: Object zero,one,two,trhee,fffour has no method 'isArray'
at Function._.mixin.observe (c:\Users\jcollum\Dev\prevision8\web\assets\js\lib\u
nderscore.observable.js:198:20)
at repl:1:6
at REPLServer.self.eval (repl.js:109:21)
at Interface.<anonymous> (repl.js:248:12)
at Interface.EventEmitter.emit (events.js:96:17)
I've never tried using it in a Node environment. I'll go check it out tomorrow, thanks.
I'm messing around with it right now but I'm not that great at node. I'm hoping to get something like require('./js/underscore.observable.js)(und)
that would load up the mixin -- where und
is the underscore require var.
I think I've got it, forking now.
_ is a special variable in Node REPL, which holds the result of the last expression.
Kind of annoying, but it's why this doesn't work as expected.