-1

It seems that in the main.js file of a Parse.com cloud code file,

the "underscore" library (toobox, whatever) is available for use when needed.

For example in this question the "underscore" library (toobox, whatever) would seem to be available and ready to use in main.js ...

// a great toolbox for dealing with collections and other stuff
var _ = require('underscore');

Parse.Cloud.define("someFunction", function(request, response) {
    ...
        _.each(players, function(player) {

... and indeed that works perfectly.

What is the "underscore" library (/whatever) ... where does it exist in the pipeline? Is it from Parse, from javascript, from something else? Why is it "available" in Parse's cloud code - that is to say, does Parse "include" it somewhere, or indeed does the issue have nothing to do with Parse, or?

Community
  • 1
  • 1
Fattie
  • 27,874
  • 70
  • 431
  • 719
  • 1
    Underscore (and lodash) are algorithm libraries you can use/import/require in your application so you don't have to waste time implementing things that have already been written and optimized by really smart people. lodash.com/docs – Daniel Lizik Sep 08 '15 at 14:37
  • 1
    yeah just a bunch of utility methods, I like them especially for collections. http://underscorejs.org/#collections – dave Sep 08 '15 at 14:42
  • Hi Guys - thanks; I appreciate that but .. "what are they"? is it a library **for any javascript project whatsoever**? Or is it something "for Parse"? or something else I don't know about? And as I ask, how is it magically available in Parse?? or is it just always available in all javascript everywere? thx ...! – Fattie Sep 08 '15 at 14:44
  • 1
    It is, indeed, a library for any JavaScript project whatsoever. You can think of it as Boost for JS. – Wolf Sep 08 '15 at 14:48

1 Answers1

1

Underscore.js is a JavaScript library which provides utility functions for common programming tasks. It is fully open source and you can find it on Github.

As you can see on NPM site, it's one of the most used library for modules hosted on NPM.

gaelgillard
  • 2,483
  • 1
  • 14
  • 20
  • What you see is the CommonJS syntax used in NodeJS. It can be converted with tools like Browserify or Babel (with the ES6 syntax) to transform it to the plain JavaScript that every browsers understand. And you welcome! – gaelgillard Sep 08 '15 at 15:59
  • CommonJS, Node, Browserify, and Babel are all _things_, but they exist fully independently of each other; this discussion seems to be conflating them pretty hard and that makes me nervous. – Evan Davis Sep 10 '15 at 20:39
  • Thanks guys. @Mathletics and Swatto - I'm still confused why it is "just there", when I'm writing parse cloud code. It seems impossible that I can say `require('any-old-library')` and it just finds it. (Unless there is a cocoapods-like central repository, or something.) My question, simply, is it the case that - let's put it this way - **the Parse sysadmins have a copy of underscore.library.something, somewhere in their system, in such a way that that library is available if I 'require' it?** Is that right?? In short, "why is it available to me there?" Thanks - a lot! – Fattie Sep 25 '15 at 13:35
  • @JoeBlow have you tried [reading the docs](https://parse.com/docs/js/guide#cloud-code-modules)? – Evan Davis Sep 25 '15 at 14:53
  • Hi @Mathletics; I'm not a j/s engineer and I don't even know where the doco would be - or what doco you mean :) It's a pretty basic question - when you do this `require` thing, how does javascript know to get the file (or whatever it is) ...? Anyways no bothers - thanks for your help so far – Fattie Sep 25 '15 at 15:07
  • https://parse.com/docs/js/guide#cloud-code-modules <- this is the doc i linked, the doc for parse.com, the service you are using. Why are you using a service without reading the documentation? – Evan Davis Sep 25 '15 at 17:29
  • http://wiki.commonjs.org/wiki/Modules/1.1 <- this is a description of how modules work in CommonJS, the format used by Parse. Parse defines a `require` function which, when given a string identifier, maps that string to a file on the filesystem which is then made available to the current module. – Evan Davis Sep 25 '15 at 17:31