How can JQuery be both function and object?

5

I know little of Javascript, and I was trying to understand how JQuery manages to be both a function and an object at the same time. I was wondering how it was developed so it could be called as function ( $() ) and e as object ( $.fn() ). Does anyone know how this works?

    
asked by anonymous 27.10.2017 / 06:14

1 answer

3

This is not from jQuery, but an aspect of JavaScript itself, where all functions are objects .

Examples:

var obj = function(){
  alert('Olá!');
}

obj.ola = "Olá de novo!";

obj(); // exibe "Olá!"
alert(obj.ola); // exibe "Olá de novo!"

Source: SOen

    
03.11.2017 / 22:56