0

Why the code inside the app.init() function not executed?

(function () {
  
  console.log('loaded here');

  function ready(callbackFunction){
    if (document.readyState != 'loading')
      callbackFunction(event)
    else
      document.addEventListener("DOMContentLoaded", callbackFunction)
  }

  var app = function (options) { 
    var app = this,
          version = 1.00;
 
    app.init = function () {
      console.log('not loaded here');
      console.log(window);
    }

    app.init();
  };
  
  ready(event => {
    console.log('dom is loaded');
    window.myApp = function (opt) { return new app(opt); };
  });
  
})();

0

1 Answer 1

3

you are never calling window.myApp as a function, instead right now you're just declaring it. Change to the following,

(function () {
  
  console.log('loaded here');

  function ready(callbackFunction){
    if (document.readyState != 'loading')
      callbackFunction(event)
    else
      document.addEventListener("DOMContentLoaded", callbackFunction)
  }

  var app = function (options) { 
    var app = this,
          version = 1.00;
 
    app.init = function () {
      console.log('not loaded here');
    }

    app.init();
  };
  
  ready(event => {
    console.log('dom is loaded');
    var opt = {};
    window.myApp = new app(opt);
  });
  
})();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.