$(document).ready(function(){
// this function is executed after the entire document is ready,
// and it will fire after window.onload
myVar = new myClass();
myVar.init();
});
Here you are trying to access a method of myVar, but your .ready()
function hasn't fired yet so myVar
has not been set to new myClass()
. It is still an undefined
variable
<script type="text/javascript">
myVar.activate(x);
// this script executes *before* the code inside your document ready function,
// so this is *before* you have set myVar = new myClass();
var_dump(myVar);
// above should output 'undefined'
</script>
If you really need/want to call this method in an onload attribute, then you should set myVar
to new myClass()
in your inline script, like this:
<script type="text/javascript">
var myVar = new myClass();
myVar.init();
myVar.activate(x);
</script>