javascript - How to call an object within $(document).ready from outside it -


the function like:

(function ($) {  	$(document).ready(function () {  		var myobject = {  			myfunction: function(){  				alert('i here');  			}  		}  	});  }(jquery));    myobject.myfunction();

how can call above?

document.ready() callbacks called in order registered (ref). 1 way achieve goal create global object, initialize in 1 $(document).ready() , call in subsequent $(document).ready().

var myobject = {};  (function($) {    $(document).ready(function() {      myobject = {        myfunction: function() {          alert('i here');        }      }    });  }(jquery));      (function($) {    $(document).ready(function() {         myobject.myfunction();          });  }(jquery));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -