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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:31:09+00:00 2026-05-20T18:31:09+00:00

This is taken from John Resig`s Learning Advanced Javascript #25, called changing the context

  • 0

This is taken from John Resig`s Learning Advanced Javascript #25, called changing the context of a function.

1) in the line fn() == this what does this refer to? is it referring to the this inside the function where it says return this?

2) although I understand the purpose of the last line (to attach the function to a specific object), I don’t understand how the code does that. Is the word “call” a pre-defined JavaScript function? In plain language, please explain “fn.call(object),” and explicitly tell me whether the object in parens (object) is the same object as the var object.

3). After the function has been assigned to the object, would you call that function by writing object.fn(); ?

var object = {}; 
function fn(){ 
  return this; 
} 
assert( fn() == this, "The context is the global object." ); 
assert( fn.call(object) == object, "The context is changed to a specific object."
  • 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-20T18:31:09+00:00Added an answer on May 20, 2026 at 6:31 pm

    call is a function defined for a Function object. The first parameter to call is the object that this refers to inside the function being called.

    When fn() is called without any particular context, this refers to the global context, or the window object in browser environments. Same rules apply for the value of this in the global scope. So in fn() == this), this refers to the global object as well. However, when it is called in the context of some other object, as in fn.call(object), then this inside fn refers to object.

    fn.call(object) does not modify or assign anything to object at all. The only thing affected is the this value inside fn only for the duration of that call. So even after this call, you would continue calling fn() as regular, and not as object.fn().

    The example simply demonstrates that the this value inside a function is dynamic.

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

Sidebar

Related Questions

Example taken from Mozilla's help page <script type="text/javascript"> re = /(\w+)\s(\w+)/; str = "John
This program taken from a book Pro JavaScript Techniques is used to create hover-like
Can the performance of this sequential search algorithm (taken from The Practice of Programming
So, I was reading up on John Resig's blog , saw his micro-templating javascript
Take a look at this awesome code from John P Bloch. What this code
So I have this code that takes care of command acknowledgment from remote computers,
My problem is this: I need to select values from groups table that do
Take this code: <?php if (isset($_POST['action']) && !empty($_POST['action'])) { $action = $_POST['action']; } if
Take this non-compiling code for instance: public string GetPath(string basefolder, string[] extraFolders) { string
In my computer this code takes 17 seconds (1000 millions times): static void Main(string[]

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.