Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8632303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:19:59+00:00 2026-06-12T09:19:59+00:00

I’m having trouble assigning some variables as within a closure scope of a javascript

  • 0

I’m having trouble assigning some variables as within a closure scope of a javascript class/jQuery plugin.

When I move into Article.initObj() as in the constructor of the Article class, I can’t see either domElement or settings in my closure scope, but I can see me and testVar. This is confusing me quite a lot. Can anyone shed some light on what be might going on here?

EDIT: I’ve tried this in both firefox and chrome.

Here’s my HTML:

<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script type="text/javascript" src="ArticleNav.js"></script>
        <script type="text/javascript">
            $(document).ready(function() {
                // Init our Viomedia article graph
                var articleList = $("#entityList").children().ArticleNav();             
            });
        </script>
    </head>
    <body>
        <div id="leftPanel" class="vpanel">
            <div id="#search">
                <label for="searchField">Search </label>
                <input style="float: right;" name="searchField" id="searchField"/>
            </div>
            <div id="tree">
            </div>
        </div>
        <div id="rightPanel" class="vpanel">
            <div id="entityList" >
                <div class="article program" id="1">
                    <div class="title">The Simpsons</div>
                    <div class="article playlist" id="2">
                        <div class="title">Classic Episodes</div>
                        <div class="article episode" id="6">
                            <div class="title">Homer the Heretic</div>
                        </div>
                    </div>
                    <div class="article season" id="3">
                        <div class="title">Season 4</div>
                        <div class="article episode" id="4">
                            <div class="title">Kamp Krusty</div>
                        </div>
                        <div class="article episode" id="5">
                            <div class="title">A Streetcar Named Marge</div>
                        </div>
                        <div class="article episode" id="6">
                            <div class="title">Homer the Heretic</div>
                        </div>
                        <div class="article episode" id="7">
                            <div class="title">Lisa the Beauty Queen</div>
                        </div>
                    </div>
                </div>
                <div class="artist article" id="7">
                    <div class="title">Electric Light Orchestra</div>
                    <div class="article album" id="8">
                        <div class="title">The Essential Electric Light Orchestra</div>
                        <div class="article album" id="9">
                            <div class="title">Disc 1</div>
                            <div class="article track" id="10">
                                <div class="title">So Serious</div>
                            </div>
                        </div>
                        <div class="article album" id="11">
                            <div class="title">Disc 2</div>
                            <div class="article track" id="12">
                                <div class="title">Last Train to London</div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="program article" id="13">
                    <div class="title">Archer</div>
                </div>
            </div>
        </div>
    </body>
</html>

Here’s my jQuery plugin:

(function($){

    var Article = function (element, options)
    {
        var me = this;
        var testVar = "I can read this";
        var domElement = $(element);

        var settings = $.extend({}, options || {});

        this.initObj = function()
        {
            me.test();
        };

        this.test = function()
        {
            console.log(testVar);
        };

        this.initObj();
    };

    var construct = function(element) {
        var element = $(element);
        // If this element already has this plugin attached to it.
        if(element.data('Article')) {
            return;
        }

        var ArticlePlugin = new Article(element);
        element.data('Article', ArticlePlugin);
    };

    $.fn.ArticleNav = function(func) {

        return this.each(function()
        {
            switch (func) {
                default:
                    construct(this);
                    break;
            }
        });
    };

}( jQuery ));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:20:00+00:00Added an answer on June 12, 2026 at 9:20 am

    domElement is available from .initObj() from the parent closure scope. Did you actually try to use it or did you just not see it in the debugger?

    If you are stepping through initObj() in the debugger, you won’t see domElement as a local variable in the debugger because it is in a higher scope, but if you do an explicit watch on it, you will be able to see it. If you write code in initObj() that references it, it will work.

    Same for settings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.