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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:18:33+00:00 2026-05-30T00:18:33+00:00

class A constructor: -> method: -> In the above example, method is not bound

  • 0
class A 
   constructor: ->
   method: ->

In the above example, method is not bound to the class and neither is constructor.

class B 
   constructor: ->
   method: =>

In this case, method is bound to the class. It behaves as you expect a normal object method to behave and has access to all of class B’s fields. But the constructor is not bound? That seems strange. So i tried the following.

class C 
   constructor: =>
   method: =>

This doesn’t compile. I would expect the syntax to be the same on all methods that are bound to a class.

I would like to regard the -> operator as a static operator and the => operator as a dynamic operator. But it doesn’t seem like you can. If you could, a method with the -> operator could not be called with super. But, in actuality, you can. Why does this make sense for the syntax of an object oriented language? This seems to not agree with most object oriented languages inheritance rules.

  • 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-30T00:18:35+00:00Added an answer on May 30, 2026 at 12:18 am

    Try looking at how the code compiles. When you use =>, the methods are bound inside the constructor. Thus, it doesn’t make any sense to use => for a constructor – when would it be bound?

    I’m not sure about your issue with static vs. dynamic operators, but you can definitely call methods defined with the -> operator with super. The only thing -> vs => affects is that the => ensures that this is the object in question regardless of how it is called.

    Summary of comments:

    Calling the difference between -> and => analogous to static vs. dynamic (or virtual) does not quite convey what those operators do. They are used to get different behavior from javascript’s this variable. For example, look at the following code:

    class C
      constructor: ->
      method1: ->
        console.log this
      method2: =>
        console.log this
    
    c = new C()
    
    c.method1()        //prints c
    f = c.method1;f()  //prints window
    
    c.method2()        //prints c
    f = c.method2;f()  //prints c
    

    The difference is in the second way we call each method: if the method is not “bound” to the object, its this is set by looking at what precedes the method call (separated by a .). In the first case, this is c, but in the second f isn’t being called on an object, so this is set to window. method2 doesn’t have this problem because it is bound to the object.

    Normally, you can think of the the constructor function automatically being bound to the object that it is constructing (thus, you can’t bind it with =>). However, its worth noting that this isn’t quite what’s happening, because if a constructor returns an object, that will be the return value of the construction, rather than the this during the constructor.

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

Sidebar

Related Questions

I know that calling a virtual method from a base class constructor can be
Does creating an object using reflection rather than calling the class constructor result in
I noticed that jUnit runs the constructor of my test class for each method
After learning of this excellent method of accessing an object placed on the stage
Sorry if this is elementary, but I've not found a good example precisely describing
Imagine a base class with many constructors and a virtual method public class Foo
Based on constructor of the class. create or destroy new methods. I often requires
I'm redesigning a class constructor in C++ and need it to catch an unspecified
Into a class constructor, I need to create some objects on the fly and
I'm writing some code for a class constructor which loops through all the properties

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.