What is the reason .on() load not working with inside script only with call function?

with above
function maps()

$(document).on('load', function()


But when try paste the whole code inside

$(document).on('load', function()
		//maps function here from function maps(){}

is not working can explain ? Same things works with .scroll or .resize but why not with .load?


The first version is calling the function maps. From what you’re saying, and without seeing the full second version, it is DEFINING the function maps, but not actually calling it.

I got that but from what the first version can run the script and the second is not? I call same .load but in another context.

Do you have this somewhere we can see it? It may be that, by defining it in the context of .load, it’s only available in that context? You could attach it directly to the global namespace by

$(document).on('load', function(){
  window.maps = function(){ ... }

But that assumes that the namespace or context is the issue. Again, do you have this somewhere as code? A pen, or a repl, or something?