Javascript method

Asked

Viewed 201 times

1

What remained to be defined in this method? ...

function fiz(){
    alert('Eu fiz, o que não fiz!');
}
eu.pensamento = fiz;
eu.pensamento();

  • 1

    eu for example.

  • No, I got it. I’m sorry, partner!

2 answers

0

If I create a variable eu, eu.pensamento is not a function? how do I define this method with the function I did, in eu.pensamento()? If you have a code as an example, it would help a lot ..

eu = 'Eu...'
function fiz(){
    alert('Eu fiz, o que não fiz!');
}
eu.pensamento = fiz;
eu.pensamento();

  • You set the global variable "me" to a string. The variable eu contains string methods, and this way you did eu.pensamento is wrong. The right way was for you to have assigned the variable "I" as a literal object, example: var eu = {} . Replace the first line with the example.

0


You need to define eu as an object. So you can build the method eu.pensamento() as a function of fiz():

function fiz(){
   alert('Eu fiz, o que não fiz!');
}

var eu = new Object();
eu.pensamento = fiz;
eu.pensamento();

console.log(eu.pensamento);

  • thanks! took my doubt

Browser other questions tagged

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