converting string to variable reference within document ready callback
I have a variable defined in the .ready callback which is passed to a global function from an event handler. I need to build up the variable name in a string, and convert it to a reference to the variable for the global function. I'd normally use bracket notation for this, but I can't find the right object to apply it to.
- $(document).ready(function()
{
- var myObj = {foo : 'bar'};
- $( 'p' ).click( function()
- {
- var partial1 = 'my';
- var partial2 = 'Obj';
- myGlobalFunc( xxx[partial1 + partial2] );
- }
- }
I can move myObj out of the callback and get this to work with 'window' in place of 'xxx', but I'd really like to do this within the callback. Is there an 'xxx' that will work?