How can Jquery be both function and object?

Asked

Viewed 34 times

5

I know little about Javascript, and I was trying to understand how Jquery can be a function and an object at the same time. I wondered how it was developed so that it could be called as a function ($()) and as an object ($.fn()). Does anyone know how this works?

1 answer

3


This is not 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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.