i have a created object outside the jquery document.ready call and then calling that object methods from inside the document.ready. it works fine on firefox, but giving error in chrome. obviously if i put that object inside the document.ready, it works fine, but then i wont able to call that object from outside the document.ready. so i need solution for this. following is the co开发者_开发百科de
var status = {
method_one: function() { ...},
method_two: function() { ...}
}
jquery(function() { // document ready
status.method_one(); // giving error here in chrome, but does not in firefox.
});
works fine for me in Chrome: http://jsfiddle.net/5s739/
are you setting the jquery
value yourself? Perhaps it should be jQuery
with a capital Q?
var status = {
method_one: function() { alert(1); },
method_two: function() { alert(2); }
}
jQuery(function() {
status.method_one();
});
you can probably test this quickly by checking if $ == jquery
or jQuery == jquery
unless you're assigning this yourself.
How about:
var status = null;
jquery(function() { // document ready
status = {
method_one: function() { ...},
method_two: function() { ...}
}
status.method_one(); // giving error here in chrome, but does not in firefox.
});
Than you can still call status outside document.ready()
精彩评论