-8
function ($, _){
    ...
    function _snackbar(content, options) {
      options = _.extend({ timeout: 3000 }, options);
      options.content = content;

      $.snackbar(options);
    }
    ...
}

source from https://thinkster.io/django-angularjs-tutorial#rendering-post-objects

It looks like that "_" and "$" are some parameters, I googled and noticed that underscore and jquery are related to these symbols. Could anyone kindly explain that what '_' and '$' stand for, how they make sense and why they are needed here? Thanks a lot.

knbk
  • 52,111
  • 9
  • 124
  • 122
yorven
  • 41
  • 6
  • 3
    By themselves, they mean nothing at all. They are just characters you can use to assign variables. The context within your code sample would depend entirely on how that function is called. – Rory McCrossan Aug 31 '16 at 14:23
  • The arguments that are passed. Can you add complete code – Tushar Aug 31 '16 at 14:23
  • Possible duplicate of [What does the $ sign mean in Jquery or JavaScript?](http://stackoverflow.com/questions/8667736/what-does-the-sign-mean-in-jquery-or-javascript) and http://stackoverflow.com/questions/5418279/what-does-means-here and 100s other dupes. – PeeHaa Aug 31 '16 at 14:28
  • Got it, thank you guys – yorven Aug 31 '16 at 15:11

1 Answers1

1

In that sample they are just simple parameters for that function.

Both letters are usually linked to jQuery library ($) and underscore library (_). But it's just "usually"...

Mayday
  • 4,680
  • 5
  • 24
  • 58
  • An underscore (`_`) being used could also imply the variable is a _private_ one, so not registrated in the global scope. As for the personal $, the dollar sign in a variable usually indicates (when I use it) that a variable is a jQuery object, rather than a regular HTML element object. – roberrrt-s Aug 31 '16 at 15:04
  • Thanks Mayday and @Roberrrt – yorven Aug 31 '16 at 15:13
  • @yorven, just remember, you cant count on any of these being any of the things said here. While these are often used for those things, you (or the writer of your plugin) can literally assign any value you desire to those variables. – Wesley Smith Aug 31 '16 at 15:15
  • @DelightedD0D got it, thank you :) – yorven Sep 05 '16 at 02:09