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

  • Home
  • SEARCH
  • 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 9273317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:05:10+00:00 2026-06-18T16:05:10+00:00

I dont understand one thing: var comein = document.getElementById(comein); var enter = new Expand({

  • 0

I dont understand one thing:

 var comein = document.getElementById("comein");

 var enter = new Expand({ elem : comein });

function Expand (options) {
    this._elem = options.elem;
    console.log(this._elem); // i have a div element    
}

Expand.prototype = {        
    check : function () {

        var comInClassName = this._elem.className; // i have an error: this._elem is undefined

        if (comInClassName == "open"){
          this.close();
        }
        if (comInClassName == "close"){
          this.open();
        }
    }
}
log_in.addEventListener("click",  enter.check, false);

Why I have an error in prototype method if in Expand i have a normal element? Thanks

  • 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-18T16:05:11+00:00Added an answer on June 18, 2026 at 4:05 pm

    It depends entirely on how you call check. If you call it like this:

    enter.check();
    

    ….then within the call, this will refer to the enter object and it will have an _elem property. If, on the other hand, you set it up to be called like this:

    enter._elem.addEventListener('click', enter.check, false);
    

    …then within the call (when the event occurs), this will not refer to enter, but rather to this._elem, and so it has no _elem property.

    This happens because in JavaScript (for now), this within a function call is defined entirely by how the function is called, not where the function is defined. If you call it as part of an expression retrieving the function reference from an object:

    enter.check();
    

    …then this refers to the object you got the function reference from. But if you call it separately, as with the addEventListener call above, it doesn’t.

    If you’re on an ECMAScript5-enabled environment (or if you have a decent ES5 shim in place), you can fix that by using Function#bind:

    enter._elem.addEventListener('click', enter.check.bind(enter), false);
    

    bind returns a function that, when called, will turn around and call the underlying function using the given this value (enter, in our case).

    More to explore (on my blog):

    • Mythical Methods
    • You must remember this
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to using numpy and one thing that I really don't understand
I'm getting to grips with Backbone.js, but one thing I don't understand is where
I saw someone using this in one answer: void methodA(const int*& var); I couldn't
I understand one of the big deals about constants is that you don't have
I don't understand why atoi() is working for every entry but the first one.
I don't understand usage for these: msleep and msleep_interruptible ... I know one interruptible
I just don't understand. It worked fine at one point but not it's not
I'm trying to get a one-to-many relationship working with grails/gorm. I don't understand how
I'm trying to understand some MATLAB source codes. I don't know exactly which one
This is one usage I found in a open source software.And I don't understant

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.