2

I've been looking at the jquery website but I don't think I'm quite understanding this as I'm not seeing any console.logs

$(document).ready(function(){
    var a=[1,2,3];
    var b='foo';
    var c={'bar':'baz'};

    $.getScript('script.js',function(a,b,c){
        console.log('how can i see a='+a+', b='+b+' and c='+c+' inside here?');
        });
    });
1
  • this works here: jsfiddle.net/rYQkx without redifining variable as local Commented Dec 18, 2013 at 11:29

1 Answer 1

3

The script is executed in the global context, so simply don't pass arguments (they're shadowing those defined by the script) :

$.getScript('script.js',function(){
    // use a, b and c here
    console.log(a);
});
Sign up to request clarification or add additional context in comments.

3 Comments

nope I can't log anything that way ether. I do this console.log(a); and I see nothing.
@BenMuircroft because i guess your variables are not globals. See when variables are on same scope: jsfiddle.net/5FCej
@BenMuircroft Then just don't declare them as arguments to the callback (i.e. change function(a,b,c) to function()).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.