0

I have some limited experience with coding in Javascript, but I can figure out most functionality using common programming logic.

I'm part of a group for a software engineering class, and our group is tasked to develop a feature for an existing piece of software. We have some input from the actual developer about where to start, but I'm getting tripped up over a few parts in the code.

A few snippets:

json.multiWordTexts = _.pickBy(json.multiWordTexts,isUsable);

and

$.each(boardContent.inks,function(i,ink){
        prerenderInk(ink,true);
    });

and

prerenderTextMark = Date.now();
    _.each(boardContent.multiWordTexts,function(text){
        if(isUsable(text)){
            prerenderMultiwordText(text);
        }
        else{
            console.log("Not usable",text);
        }
    });

What I can't figure out is what the the &. and _. actually do. I've searched around everywhere, but I haven't been able to find anything that identifies those things. My first thought was that it was a way to write a foreach statement, but they are used with other things as well.

The code is in a javascript file, so I'm assuming it's javascript. I've never seen it before in other pieces of code, so I have no idea what its functionality is. Can anyone enlighten me?

Jimmy Fort
  • 53
  • 4
  • _. is underscore plugin and $ is used for JQuery. You can find about underscore on http://underscorejs.org/ and about JQuery on https://jquery.com/ – No one Jan 24 '18 at 20:28
  • 1
    Possible duplicate of [Can someone explain the dollar sign in Javascript?](https://stackoverflow.com/questions/846585/can-someone-explain-the-dollar-sign-in-javascript) – Evan Trimboli Jan 24 '18 at 20:30

5 Answers5

1

The $ is probably jQuery and the _ is probably Lodash.

You should be able to determine what libraries those symbols are by checking the import statements (if you're using those) or by checking what libraries are linked in the HTML (check the <script> tags).

pete
  • 24,141
  • 4
  • 37
  • 51
  • Did some poking around in the html files and was able to find out what was included. Found the scripts that are being used and I think I'm good from here. Much appreciated! – Jimmy Fort Jan 24 '18 at 20:46
1

The $ and _ are in Javascript valid names for objects. Which means that $ and _ might as well have been called jQuery and Underscore, so that it basically means

jQuery.each(boardContent.inks, function(i, ink){
    prerenderInk(ink, true);
});

The point here being - Javascript identifiers are unicode, which means you can use almost any character you'd like for method names and so forth.

Frederik Spang
  • 3,379
  • 1
  • 25
  • 43
0

They are javascript frameworks:

_ : Underscore.js or Lodash

$ : JQuery

Wyns
  • 321
  • 1
  • 5
0

& is ampersand.js

_ is lodash.js

They both provide useful functional programming helpers.

Mohd Asim Suhail
  • 2,176
  • 1
  • 16
  • 23
0

$ is usually a symbol for jQuery, _ is usually a symbol used for underscore or lodash. I used the word usually because they are regular variables assigned when you include the library.

To show you that they are assigned like any other symbol, here is an example from the jQuery source code:

jQuery.noConflict = function( deep ) {
    if ( window.$ === jQuery ) {
        window.$ = _$;
    }

    if ( deep && window.jQuery === jQuery ) {
        window.jQuery = _jQuery;
    }

    return jQuery;
};
Jeremie
  • 11
  • 1