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 6796491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:29:44+00:00 2026-05-26T18:29:44+00:00

Just curious about jQuery/Javascript and referring to options within variables. So, I wrote a

  • 0

Just curious about jQuery/Javascript and referring to options within variables.

So, I wrote a little plugin that when I call "populate" will fill in some text. Very basic. Here’s what I’m trying to do:

var foo = {
    msg1: "Hey",
    msg2: this.msg1 + "how",
    msg3: this.msg2 + "are",
    msg4: this.msg3 + "you",
    msg5: this.msg4 + "doing",
    msg6: this.msg5 + "today"
}

$("#bar").populate({text: foo.msg6});

So when the .populate plugin is called, #bar will get "Hey how are you doing today" added to it.

The populate plugin is hard to explain but trust me it’s working great and not the issue. I’m just curious if this sort of organization of variables and options is possible, as it seems cleaner, more "semantic", and more organized to me than just a bunch of variables referring to other variables…

  • 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-05-26T18:29:44+00:00Added an answer on May 26, 2026 at 6:29 pm

    this only has meaning in an execution context. When you define a function, a scope chain is created for that function that will be used whenever that function enters the current execution context. When that occurs, this will become defined (at runtime). See this for more details.

    In your example, you are not defining any new scope chains, because you are not creating any methods on your object. Therefore, when you refer to this, you are referring to whatever this is whenever you make your foo object. Most likely, you are working in the global space, so this will be window (if you’re in the browser), but it could be another object that has a function that you are currently executing in. For example:

        var myScopeObj = {
            myMethod: function() {
                var foo = {
                    msg1: "Hey",
                    msg2: this.msg1 + "how",
                    msg3: this.msg2 + "are",
                    msg4: this.msg3 + "you",
                    msg5: this.msg4 + "doing",
                    msg6: this.msg5 + "today"
                };
                var foo2 = foo.msg6;
            }
        };
    

    There are a couple of possibilities in the above example:

        myScopeObj.myMethod();  // 'this' refers to myScopeObj
    

    or

        var method = myScopeObj.myMethod;
        method();  // 'this' refers to window
    

    or

        myScopeObj.myMethod.call(window);  // 'this' refers to window
    

    What you could do is use make a constructor function for your object, and use this to map properties.

        function Foo() {
            this.msg1 = "Hey";
            this.msg2 = this.msg1 + "how";
            this.msg3 = this.msg2 + "are";
            this.msg4 = this.msg3 + "you";
            this.msg5 = this.msg4 + "doing";
            this.msg6 = this.msg5 + "today";
        };
        var foo = new Foo();
        $("#bar").populate({text: foo.msg6});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just curious about the role that self plays within an object. I
I'm just curious about this. It strikes me that the behavior of a StringBuilder
i was just curious about webbot project and i wish that i could create
I am just curious about the java memory model a little. Here is what
I'm mostly just curious about this. Do assemblies that would be considered part of
I'm just curious about which among variables and methods inside a class were initialized
I am currently learning jQuery, and I am curious about something. For functions that
Just curious about the encodings that system is using when handling string storing(if it
I'm just curious about the efficiency of pattern matching in Haskell. What is a
I'm just curious about this really, does anyone know why they broke convention on

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.