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

2

I'm having the following error: "Myfunction is not defined"

With the structure below:

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

   minhafuncao: function() {
      console.log("oi");
   }
});
    
asked by anonymous 29.06.2017 / 16:18

1 answer

3

Use this to indicate the scope of the function:

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

  minhafuncao: function() {
    console.log("oi");
  }
}
obj.init();
    
29.06.2017 / 16:20