Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
89
rated 0 times [  95] [ 6]  / answers: 1 / hits: 69593  / 16 Years ago, wed, february 25, 2009, 12:00:00

I haven't found a good reference for declaring my own functions inside the



jquery.ready(function(){});


I want to declare them so they are inside the same scope of the ready closure. I don't want to clutter the global js namespace so I don't want them declared outside of the ready closure because they will be specific to just the code inside.



So how does one declare such a function...and I'm not referring to a custom jquery extension method/function...just a regular 'ol function that does something trivial say like:



function multiple( a, b ){ 
return a * b;
}


I want to follow the jquery recommendation and function declaration syntax. I can get it to work by just declaring a function like the multiply one above...but it doesn't look correct to me for some reason so I guess I just need some guidance.


More From » jquery

 Answers
13

I believe that you would be okay just declaring the function inside the ready() closure, but here you can be a bit more explicit about the local scoping:



jQuery.ready(function() {

var myFunc = function() {

// do some stuff here

};

myFunc();


});

[#99928] Wednesday, February 18, 2009, 16 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristopherh

Total Points: 402
Total Questions: 117
Total Answers: 84

Location: Monaco
Member since Fri, Sep 24, 2021
3 Years ago
;