js - require("underscore")
Is there anyone else that has been successful in using the underscore package in the js object? I'm able to use my own js code via the help instructions, but I just can't figure out to get underscore to work. I'll run all sorts of flavors of the require statement:
var _ = require("underscore");
var y = [1, 2, 3];
_.each(y, function(v) { post(v) });
all to to no avail. The js object doesn't appear to find the package reporting something like "js: test.js: Javascript TypeError: _.each is not a function, line 6".
Found the answers.
First, the limitation of no subdirs appears to remain an issue. Underscore only worked once I moved the js file into the same directory as the patch. I suspect this generalizes to the Max search path, but I didn't test that out.
Second, the require statement had to be updated to reference the main underscore (_) function defined by the underscore script:
var _ = require("./underscore.js")._;
This modification stemmed from an answer from Florian (thanks).