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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:01:53+00:00 2026-06-02T10:01:53+00:00

I’ve javascript object var Bucket = function(id) { this.id = id this.items = []

  • 0

I’ve javascript object

var Bucket = function(id) {
     this.id = id
     this.items = []
}
Bucket.prototype.add_item = function(item) {
     //some uniquness checking code here
     this.items.push(item);
}

For some reason, when I instantiate the object and try to add an item, I get an error

var bct = new Bucket
bct.add_item(some_item)

'undefined' is not an object (evaluating 'this.items.push')

This error occurs even though the item is getting added to the array of the bucket

console.log(bct.items)
>> [some_item]

I used console.log(this) inside the add_items method and I see two entries being logged from the same line

>Object myjavascript.js:28
>DOMWindow myjavascript.js:28

There are some other libraries included on the page

  1. Google Analytics
  2. jQuery
  3. Colorbox plugin for jQuery
  4. jQuery Easing

Any ideas what is binding this object to Window?


FOUND IT (Edit)

somewhere else on the page, I was using a jquery ajax call in combination with my object… and it was binding it… sorry for not posting all of the relevant code…

  • 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-02T10:01:54+00:00Added an answer on June 2, 2026 at 10:01 am

    You say “the item is getting added”, but that is irrelevant, because according to your logging you have two calls to the method, one of which is correct. You need to focus on the incorrect one.

    Make sure you have a debugger in your browser (e.g. Chrome with the Web Inspector opened), and modify your code like so:

    Bucket.prototype.add_item = function(item) {
         if (this === window) debugger;
         //some uniquness checking code here
         this.items.push(item);
    }
    

    This will automatically pause your code when the erroneous call has occurred. Then, look at the call stack to find out what is calling your add_item function other than as a method.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the

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.