0

I've defined the following javascript object:

var WealthyLaughingDuckControl = {
    users: [],
    setUsers: function(new_users) {
        this.users = new_users;
    }
};

I would like it to be available inside the chrome/firebug's javascript console:

> WealthyLaughingDuckControl
// console result goes here

At now, I get:

> ReferenceError: WealthyLaughingDuckControl is not defined

How can I do that?

2
  • 1
    do you have the page where we can see this? Also please tell me you don't have that object within $(document).ready statement Commented Mar 29, 2013 at 22:00
  • Oops... It is wrapped with $(document).ready( function() { :/... thanks for help! Commented Mar 29, 2013 at 22:04

2 Answers 2

4

remove the var keyword, or append it to window: window.WealthyLaughingDuckControl

Sign up to request clarification or add additional context in comments.

3 Comments

Could you please take a look at this answer - the author said there's no difference between var and non-var if it's declared in the global scope. I did define my variable in the global scope and in fact - with var it's inaccessible inside js console, and without - it's accessible. Is this answer incorrect?
Maybe you are not in the global scope when using var, review in the code of your actual page instead of the code you write in your editor, maybe your environment wraps any javascript code you write, what exactly is your environment? is it plain Javascript?
My env is NetBeans IDE. I don't expect it to wrap it in anything. Well, my variable was defined in the $(document).ready( function() { though... So it was not global, afterall (sorry...)
3

Define WealthyLaughingDuckControl at the top level i.e. not in any function.

Comments

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.