What is the difference between "$ .FunctionName ()" and "FunctionName ()"?

what's the difference between jQuery function

$.FunctionName = function(){ alert('Hello!') }

and normal javascript function?

function FunctionName(){ alert('Hello!') }
+3
source share
2 answers

The first becomes a static method of the jQuery object. The latter becomes just a regular function.

The only difference is really the owner of the function. The jQuery object / constructor owns the first method, and the object windowbelongs to the second method, assuming that it is not defined in another scope of the function.

, , , jQuery. , .

+6

. .

, - ( not $), my_lib={}, ,

my_lib.FunctionName = function(){ alert('Hello!'); }

my_lib={
    FunctionName: function(){ alert('Hello!'); }
}
0

Source: https://habr.com/ru/post/1772955/


All Articles