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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:31:09+00:00 2026-06-12T11:31:09+00:00

In the following code, the first function is not bound to obj , but

  • 0

In the following code, the first function is not bound to obj, but the second function is, so f() returns fifi and g() returns Mark Twain as expected. But the 3rd attempt, it is by (obj.getCallBack) first, which is now a function, and then it is invoked, essentially it should be the same as the f case. But they do print out Mark Twain instead. Why are they not bound to obj using bind() but still got executed with this pointing to obj?

(the 4th attempt is just a usual invocation of a method, and this should bind to the object on which the method is invoked on).

(tested on the current Chrome, Firefox, and IE 9)

window.name = "fifi";

var obj = {
    name: "Mark Twain",
    getCallBack: function() {
        return this.name;
    }
}

var f = obj.getCallBack;
var g = f.bind(obj);

console.log(f);
console.log(f());

console.log(g);
console.log(g());

console.log((obj.getCallBack)());
console.log(obj.getCallBack());
  • 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-12T11:31:10+00:00Added an answer on June 12, 2026 at 11:31 am

    You are forgetting that if a function is called as a property of some object, that object will be the this for the call. So:

    obj.getCallBack() //The function referenced by `obj.getCallBack`
                        //is called as a property of `obj`, so obj will be `this`
                        //for the call
    
    f()    //The function referenced by f, is not called as a property of some object so
             //`this` will depend on strict mode.
    

    After these basic rules, the bound function will be invoked, which can be thought of as a proxy function (any shim does this) that uses .call/.apply to explicitly set the context for the target function. So the this value for the proxy function doesn’t matter, but behind the scenes it was set by the basic rules.

    Edit:

    (obj.getCallBack) does not return the function as value, because getValue is not called.. So it is exactly the same as obj.getCallback and the first post applies.

    So you can do this and not get an error:

    (obj.getCallback) = 5;
    

    As opposed to:

    (function(){}) = 5; //invalid assignment
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following code, the first log statement shows a decimal as expected, but
I have the following code: Public Shared Function GetAvailableManufacturers() As List(Of Manufacturer) 'first get
How to DRY the following code and call the first initializer from the second?
I'm getting a function not defined Javascript error with the following code, which uses
In the following code the first and second images with anchors have links and
I have the following code: $(document).on('hover', '.tic_cont:not(.disabled_ticket)',function () { $(this).stop().find(.tic_icon).animate({ top: '-=16px' }, 250);
The following code (without showing it all) is my first attempt at using classes.
Does the following code contain a memory leak of the first three characters in
I'm using the Code First approach and have the following Model: public class Person
I've in the following code the progressbar working on the first page load. after

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.