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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:32:55+00:00 2026-06-04T12:32:55+00:00

I am learning Node.js recently. I have a question about the function util.inherits in

  • 0

I am learning Node.js recently. I have a question about the function util.inherits in Node.js. Can I use extends in coffeescript to replace it? If not, what are the differences between them?

  • 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-04T12:32:56+00:00Added an answer on June 4, 2026 at 12:32 pm

    Yes, you can use extends in place of it.

    As for the differences? Let’s start with a look at CoffeeScript:

    class B extends A
    

    Let’s look at the JavaScript the CoffeeScript compiler produces for this JavaScript:

    var B,
      __hasProp = {}.hasOwnProperty,
      __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
    
    B = (function(_super) {
    
      __extends(B, _super);
    
      function B() {
        return B.__super__.constructor.apply(this, arguments);
      }
    
      return B;
    
    })(A);
    

    So, __extends is used to declare the inheritence relationship between B and A.

    Let’s restate __extends a bit more readably, in CoffeeScript:

    coffee__extends = (child, parent) ->
      child[key] = val for own key, val of parent
    
      ctor = ->
        @constructor = child
        return
      ctor.prototype = parent.prototype
    
      child.prototype = new ctor
      child.__super__ = parent.prototype
    
      return child
    

    (You can check that this is a faithful reproduction by compiling it back to JavaScript.)

    Here’s what’s happening:

    1. All the keys found directly on parent are set on child.
    2. A new prototype constructor ctor is created, with its instances’ constructor properties set to the child, and its prototype set to the parent.
    3. The child class’s prototype is set to an instance of ctor. ctor‘s constructor will be set to child, and ctor‘s prototype itself is parent.
    4. The child class’s __super__ property is set to parent‘s prototype, for use by CoffeeScript’s super keyword.

    node’s documentation describes util.inherits as follows:

    Inherit the prototype methods from one constructor into another. The
    prototype of constructor will be set to a new object created from
    superConstructor.

    As an additional convenience, superConstructor will be accessible
    through the constructor.super_ property.

    In conclusion, you don’t need to use util.inherits if you’re using CoffeeScript’s classes; just use the tools CS gives you, and you get bonuses like the super keyword.

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

Sidebar

Related Questions

Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
Learning about notifyAll made me question something about notify: in a typical situation we
I have been just learning redis and node.js There are two questions I have
I'm in the process of learning Node.js and have been playing around with Express
I am trying my hand at learning node.js using coffeescript but am having trouble
I am learning linked list operations and have a question related to parameter passing.
I'm learning a lot about the Views in Drupal, but can't figure how to
I am learning and trying simple example using node.js and mongoskin. here is my
I am learning a book on data structures, and complied their node in linked
For use in a language-learning web application, do you know of data structures and

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.