Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- calling & defining functions using funcName() vs. window['funcName']()


sssweb - 5:25 pm on Jan 4, 2013 (gmt 0)


I'm getting errors in different situations when I don't use the right combination of funcName() & window['funcName'] in defining and calling functions. The errors mainly come up in the context of:

jQuery.noConflict();
jQuery(document).ready(function($) {
});

but crop up more in some cases if calls & defs are in different files.

I've run several tests on the various combinations and found the following patterns.

If the defs ARE w/in (doc).ready, these combinations do not work:
1) window['funcName']() call with funcName() def
2) funcName() call & def (exception: works if both are in the same file)

If the defs are NOT w/in (doc).ready, all combinations work. Unfortunately, the defs must go in (doc).ready because they contain jQuery calls.

Questions:

1) Is there a rule of thumb for using the window[] designation vs. not

2) Is there some way to code it so that it works in every case?


Thread source:: http://www.webmasterworld.com/javascript/4533285.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com