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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:35:41+00:00 2026-05-31T14:35:41+00:00

For example, if I have the object: function Website(){ this.images = []; } Website.prototype.getImages

  • 0

For example, if I have the object:

function Website(){
    this.images = [];
}

Website.prototype.getImages = function(){
    jQuery('img').each(function(key, val){
        this.images.push(val.src);
    })
}

and I try to call website.getImages() I get this error: TypeError: Cannot call method 'push' of undefined

So, in order to fix this, I would do:

Website.prototype.getImages = function(){
    var images = this.images;
    jQuery('img').each(function(key, val){
        images.push(val.src);
    })
}

But I don’t see this solution as clean, because what if im trying to access several variables.

Is there a cleaner and better way to do this?

  • 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-31T14:35:43+00:00Added an answer on May 31, 2026 at 2:35 pm

    You can do this:

    Website.prototype.getImages = function(){
        var self = this;
        jQuery('img').each(function(key, val){
            self.images.push(val.src);
            // self.someOtherProperty
            // self.someMethod()
        })
    }
    

    In a general sense this is set according to how a function is called, so as soon as you nest functions you have to do something to ensure this is set correctly for the inner function, e.g., .call() or .apply() – or .bind(), though .bind() isn’t supported by IE until version 9.

    jQuery functions that take callbacks always set this to something logical – in most cases the particular DOM element being processed at the time. But of course that doesn’t help when you want it to be something else.

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

Sidebar

Related Questions

Example: I have an class that inherits from UIImageView. An object creates an instance
How to sort list of date object ? For example I have unsorted list
Can a class return an object of itself. In my example I have a
If I have a Range object--for example, let's say it refers to cell A1
Does anyone have an example using the table object in YUI library. More specifically,
For example lets say I have a JSON object that contains states and cities.
I have an Employee object I am showing in inputtext. For example, the firstname
For example: I'm creating a CSV file and I have a CsvOptions object which
Here's a simplified example of an object I have. What I would like to
I have the following example code: class A(object): def __init__(self, id): self.myid = id

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.