what does $ mean here in JQuery

后端 未结 4 1696
甜味超标
甜味超标 2021-01-28 05:46

In the following

var obj = { one:1, two:2, three:3, four:4, five:5 };
    $.each(obj, function(i, val) {
       console.log(val);
    });

what

4条回答
  •  迷失自我
    2021-01-28 06:04

    $ is referring to the jQuery function.

    In JavaScript, a function is a special kind of object.

    You can create a function and add properties to it like any other object.

    var $ = function(message) { alert(message); };
    
    $.prop1 = 'val1';
    $.prop2 = 'val2';
    
    $("Hello world");
    
    alert($.prop2);
    
    alert($ instanceof Object);   /* This will be "true" */
    alert($ instanceof Function); /* This will be "true" */
    

提交回复
热议问题