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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:42:36+00:00 2026-06-11T21:42:36+00:00

In my application,I use following codes: (function(){ var app={ toHomePage:function(){ var that=this; var handler={

  • 0

In my application,I use following codes:

(function(){
    var app={
        toHomePage:function(){
            var that=this;
            var handler={
                xx:function(){
                    //now I have to call the clear method.
                    // 1) app.clear();
                    // 2) that.clear()
                }
            };
        },
        resize:function(){},
        clear:function(){}
    }
})();

I want to know in the handler method, use app or that?

  • 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-11T21:42:37+00:00Added an answer on June 11, 2026 at 9:42 pm

    Note that in a function, this is set entirely by how you call the function. If you will only ever call the function using:

    app.toHomePage()
    

    then within the function this will reference app. However, if someone does:

    var x = app.toHomePage;
    ...
    x();
    

    then this within the function will initially be undefined, so it will be set to the global object or, in strict mode, to undefined. The same for apply and call, where this can be set to anything.

    So likely better to just use app, since the identifier is within a closure and therefore unlikely to change its name. BTW, this is a common dilemma.

    Edit

    To explain the listener case:

    <input type="button" onclick="app.toHomePage();" ...>  // `this` is app.
    
    input.addEventListener('click', app.toHomePage, false);  // `this` is the input element.
    
    input.onclick = app.toHomePage;  //`this` is the input element.
    
    input.attachEvent('onclick', app.toHomePage);  // this is window
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following ember.js code: app.js: Game = Ember.Application.create({ ready: function() { Game.gameController.getChallenge();
For stand-alone java application I can use the following codes to load jar lib
i am creating simple call filter application which restrict unwanted calls. i use following
I use the following event to call when the application will close in Internet
I have the following code which works: $(document).ready(function() { var xhr = false; func_two();
I have the following Node.js code: var express = require('express'); var app = express.createServer(express.logger());
I have the following code. var d3_ad = 1; function displayD3Ad(){ var query_string =
I put the following method in my application.js file. var formhandler = function() {
I use the following code to allocate a Console for a WinForm application. The
In my application, which I test on emulator, I use the following code 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.