I’m developing some library and created this buggy code:
//-------------------
Gmaps = {};
Gmaps.map = new Gmaps4RailsGoogle(); //there exists a default callback function in the created object
function load_map() {
Gmaps.map.callback();
};
window.onload = load_map();
//--------------------
Gmaps.map.callback = function(){ alert('ok'); }
I thought, because the whole page is loaded, that callback would have been changed and alert message displayed.
But it’s not the case and I haven’t any error message in firebug.
If I then execute Gmaps.map.callback() in console, it works fine.
Is there any reason why the callback isn’t overriden?
For context sake, code between --------- is created by the library but developers would be able to override some functions in his html.
You’re not executing
load_maponload. You’re executing it immediately here:and storing it’s return value inside
window.onload, so nothing is happening onload. Just change that line to: