JS: not defined function error (when calling one function inside another)

Asked

Viewed 86 times

2

I’m having the following error: "my name is not defined"

With the structure down:

var myobject = object.extend({
   init: function () {
        minhafuncao();
   },

   minhafuncao: function() {
      console.log("oi");
   }
});
  • Related: https://answall.com/questions/37770/qual-a-diferen%C3%A7a-entre-this-e-this-e-this/

1 answer

3


Use the this to indicate the scope of the function:

var obj  = {
  init: function() {
    this.minhafuncao();
  },

  minhafuncao: function() {
    console.log("oi");
  }
}
obj.init();

  • Hello, I edited my question because I saw that things were missing. I tried to do as mentioned but it did not work, continues the error. :(

  • What is object.extend @sabrinabgbc? It’s from some other library?

  • is just to staunch the object

  • It worked, thank you !

Browser other questions tagged

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