Function equivalent to $() in a Javascript Object

Asked

Viewed 31 times

0

My idea is this, as I have many repeated tasks, I created a Javascript object and access the functions related to it through the ., for example:

Objeto.funcao(params)

But I need something like jQuery that uses so much $() as $.().

How can I assign a function equivalent to $()? I tried it this way>

const $ = {
   $: function(text) { alert(text) }
   f1: function(text) { alert(text) }
   f2: function(text) { alert(text) }
}

$('texto padrao') // erro gerado pelo browser dizendo que precisa acessar como objeto

$.f1('texto f1') // retorna alert dizendo 'texto f1'
  • Set $ as a function (const $ = Function...) and then "hang" F1 functions, F2 in function ($.F1 = Function...). A function is also an object in JS, so you can put penduricalhos in it.

  • Thank you Exp, helped me a lot

No answers

Browser other questions tagged

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