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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:41:54+00:00 2026-05-14T06:41:54+00:00

if in a literal object i try to reference a function using this inside

  • 0

if in a literal object i try to reference a function using “this” inside a nested property/function, this don’t work. Why? A nested property have it’s own scope?

For example, i want to call f1 from inside d.f2:

var object = {    

  a: "Var a",
  b: "Var b",
  c: "Var c",

  f1: function() {
    alert("This is f1");
  },

  d: {
      f2: function() {
       this.f1();
    }
  },

  e: {
      f3: function() {
        alert("This is f3");
     }
  }
}

object.f1(); // Work
object.d.f2(); // Don’t Work.
object.e.f3(); // Work

Thanks, Andrea.

  • 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-14T06:41:54+00:00Added an answer on May 14, 2026 at 6:41 am

    this refers to d inside f2 and not object. You could store a reference to object, or call object directly, or use call/apply to call the function and explicitly tell it what this means inside that function:

    object.d.f2.call(object); // now this refers to object inside f2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JS object property defined in an object literal: reqHeader: [{name:'Chris'},{age:'06'}] which
I have this Object Literal: var RPSPlayer = {....} and I want to make
I created an object literal in JS, but wanna to access a property without
Let's say you have an object literal: var d = { x: +'35', y:
I've been experimenting with using Javascript object literal notation vs functions with prototypes and
How do I access the name of an item in an Object Literal using
I have a simple object defined by an object literal, and have a couple
I have a user control I'm building (ASP.NET 3.5, using C#). This control is
I have an object literal where I can set a persons name. In another
I found myself in an interesting situation. I am using an object literal to

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.