0

In the following code, what does the empty jQuery selector $() mean? Does it mean $(document)?

 var menu = {
  setting:{
      isSimpleData:true,
      treeNodeKey:"mid",
      treeNodeParentKey:"pid",
      showLine:true,
      root:{
          isRoot:true,
          nodes:[]
      }
  } ,
  loadMenuTree:function(){
      $("#menuTree").zTree(menu.setting, privilegeDate);
  }
};

$().ready(function(){
    menu.loadMenuTree();
});
Isaac
  • 11,409
  • 5
  • 33
  • 45
user7693832
  • 6,119
  • 19
  • 63
  • 114
  • https://api.jquery.com/ready/ – epascarello Apr 06 '17 at 01:59
  • Possible duplicate of [Can someone explain the dollar sign in Javascript?](http://stackoverflow.com/questions/846585/can-someone-explain-the-dollar-sign-in-javascript) – Eli Sadoff Apr 06 '17 at 02:01
  • "How to understand the `$()`?" [read the api](http://api.jquery.com/jquery/), [and the code](http://code.jquery.com/jquery.js). – zzzzBov Apr 06 '17 at 02:07

1 Answers1

0

does it mean $(document)?

No, it means an empty jQuery collection, but $.fn.ready doesn’t actually care what’s in the jQuery collection:

> $().length
0

> $.fn.ready
function (a){return n.ready.promise().done(a),this}

Note how it doesn’t make use of this except to return it for chaining. You could use $(document).ready, $().ready, $('body').ready, $('blink').ready… but the only non-deprecated way is by passing the listener to the jQuery function itself:

$(function () {
    menu.loadMenuTree();
});
Ry-
  • 218,210
  • 55
  • 464
  • 476
  • Whats meaning of `$.fn`? – user7693832 Apr 06 '17 at 02:11
  • @244boy: It’s the jQuery prototype. jQuery collections are instances of the `jQuery` type, and they inherit all their properties from `jQuery.prototype`, for which `$.fn` is shorthand. – Ry- Apr 06 '17 at 02:15