Doubt Javascript methods [duplicate]

0

Greetings

I'm having a question about methods in javascript. Can anyone tell me if this is a method and what kind of method it is.

nomeMetodo : function (){
  //code
}

In case it would not be like this ...

function nomeMetodo () {
  //code
}
    
asked by anonymous 27.08.2018 / 16:45

1 answer

0

Both forms are correct.

javascript works with the concept of anonymous function, if it is called anonymous just because you do not need to define a name for it, as below.

function (){ //code }

This anonymous function will usually be used when you need to assign the function to a variable

var nomeMetodo = function (){ //code }

or create a function on an object:

var x = { a: 2, nomeMetodo: function() { return this.a; } }

In this case if you call x.name () it will return the value of

Everything will depend on how you use your function ... if you want to know a little more, I recommend starting with MDN documentation .

    
27.08.2018 / 16:59