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); }; }); })();
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); }); })();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.