That code is relying on The Horror of Implicit Globals¹, where assigning to an undeclared identifier creates a global variable.
To get the error you've described, the ready "event" would have to have already fired before your code is run, because jQuery's ready feature is chaotic: If the page is already ready, it calls its callback synchronously; if not, it calls it asynchronously.
If it were calling the callback asynchronously, you wouldn't be getting an error, because the code assigning to gsdk would have run before the code in the callback, creating the global and giving it its value.
In any case, the fix is:
Declare gsdk, don't rely on the horror of implicit globals, and
Move the initialization of it above your ready code, so that if your ready callback is called synchronously, gsdk is initialized and ready for use.
E.g.:
// 1. Declare the variable, don't rely on The Horror of Implicit Globals.
// 2. Make certain it has its value before setting up your `ready` callback, since
// apparently you're doing this when the page is already ready.
var gsdk = {
init : some function...
};
$(document).ready(function(){
gsdk.init();
});
¹ (That's a post on my anemic little blog.)
gsdk = {}in front of$(document).ready()?);is there I missed it...gsdk = {}any different if both the function and variable are in the global execution context<script src="js/jquery-1.11.3.min.js"></script>is there in html file before adding my javascript file