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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:38:25+00:00 2026-05-29T20:38:25+00:00

This is probably pretty easy, yet I am confused, so maybe I might still

  • 0

This is probably pretty easy, yet I am confused, so maybe I might still learn something more today. I am trying to do the following:

var myObj = {};
myObj.src = {}
myObj.src.A = ['1.png','2.png','3.png'];
myObj.A = new Image();
myObj.A.src = this.src.A[0];

This will result in an Uncaught TypeError: Cannot read property 'A' of undefined error.
When I use myObj.src.A[0] instead of this it is working fine.

What would be the correct way to use this in this context?

  • 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-29T20:38:26+00:00Added an answer on May 29, 2026 at 8:38 pm

    The this keyword is always different depending on the scope involved. In the code snippet you’ve posted above, assuming that you’re just putting this in the document somewhere in the head, this refers to the page itself. So, it’s fairly obvious at that point that this.src.A will be undefined. If you were to apply an event to it with a delegate such as:

    myObj.click = function() {
        alert(this.src.A[0]);
    }
    

    The this keyword receives a new scope belonging to the owner of the delegate (in this case myObj). this is very easy to track so long as your clearly define your scopes and your scope boundaries.

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

Sidebar

Related Questions

This is probably a pretty easy one, but I'm trying to think of the
This is probably a pretty basic question, but just something that I wanted to
I'm very new to Android programming, so this is probably something pretty basic. I
I'm new to WPF so this is probably a pretty easy problem. I open
I am pretty new to MySQL...so I am sure this is probably an easy
OK, this is probably pretty easy, but I am just having a knuckle of
I'm pretty new to PHP so this is probably a pretty easy answer. Anyways
This is probably a pretty easy to answer question, but I can't find the
Ok this is probably pretty easy, but I've been fiddling with it four an
Alright, so this is probably a pretty easy question to answer, but I'm struggling

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.