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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:17:03+00:00 2026-06-07T15:17:03+00:00

I always assumed that some_function(…) was exactly the same as some_function.call(this, …) . This

  • 0

I always assumed that some_function(...) was exactly the same as some_function.call(this, ...). This seems not to hold true for calls in constructors / an object construction context:

function Class(members, parent) {
    function Ctor(value) {
        members.__init__.call(this, value);
        return this;
    };
    Ctor.prototype = members;
    Ctor.prototype.__proto__ = parent.prototype;
    return Ctor;
}

var Base = Class({
    __init__: function(value) {
        this.value = value;
    }
}, {});

var Child = Class({
    __init__: function(value) {
        // Base(value*2); ← WON'T WORK AS EXPECTED
        Base.call(this, value*2); // works just fine
    }
}, Base);

In Child.__init__ it in necessary to use the explicit call to Base.call(this, value). If I don’t use this lengthy expressing, this would name the global object (window in browsers) in the called base constructor. With "use strict" an error would be thrown as there is no global object in strict mode.

Can someone please explain why I have to use Func.call(this, ...) in this example?

(Tested with Node.js v0.6.12 and Opera 12.50.)

  • 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-07T15:17:04+00:00Added an answer on June 7, 2026 at 3:17 pm

    Calling a function with .call is different from just invoking it with (). With .call you explicitly set the value of this for the call in the first argument. With normal invocation, the this value will implicitly be the global object or undefined, depending on whether strict mode is enabled or not.

    func.call({}, 1); //Call the function func with `this` set to the object and pass 1 as the first argument
    
    func(1); //Call the function func with 1 as the first argument. The value of this inside the function depends on whether strict mode is on or off.
    

    See .call


    I always assumed that some_function(…) was exactly the same as
    some_function.call(this, …). This seems not to hold true for calls
    in constructors / an object construction context:

    That’s not true, they are never the same. You are probably confusing it with calling a function as a property of some object. obj.method() will mean that obj is the value of this for the method call and it would be effectively the same as obj.method.call(obj).

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

Sidebar

Related Questions

Why do IDE's complain about leaking this in constructor? I've always assumed that it's
For some reason I have always assumed that most of the time a variable
Is it safe to assume that java.util.concurrent.CompletionService.take().isDone() will always return true? If so, why
The Salesforce.com API seems to assume that you will always use the app as
I'm trying to get this resolved in .NET 2.0 and unfortunately that is not
I had always assumed that the first entry in sys.path by default was the
I've always assumed that - in the absence of constructor parameters - the parentheses
I had always assumed that the Python interpreter did no optimizations without a -O
I understand that there are several questions on OOD; this one is not a
Is it safe to assume that $_SERVER['REMOTE_ADDR'] always returns a IPv4 address ? Thanks!

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.