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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:49:28+00:00 2026-06-16T19:49:28+00:00

I am building a Node.js application using object oriented coffeescript. I have a super

  • 0

I am building a Node.js application using object oriented coffeescript.

I have a super class with a static method like:

class RedisObject
 @find: (id, cb) ->
    client.HGETALL "#{@className()}|#{id}", (err, obj) =>
      unless err
        cb(new RedisObject(obj, false))

There is a subclass like

  class User extends RedisObject

When I call find() on the User class I want it to pass a instance of User instead of RedisObject to the callback function.

I tried to realize this by getting the class name of the actual class the method is called on by using

@constructor.name

and use eval() to generate an instance from it – but the problem is that the subclass will be undefined from within the superclass.

How can I realize the behaviour of getting different types of instances returned by the find method depending on which class it is called on, without having to override it in each subclass?

  • 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-16T19:49:29+00:00Added an answer on June 16, 2026 at 7:49 pm

    I’m not an expert in CoffeeScript, but wouldn’t this work?

    class RedisObject
      whoami: () -> "I am a RedisObject"
      @find: () ->
        new this()
    
    class User extends RedisObject
      whoami: () -> "I am a User"
    
    console.log RedisObject.find().whoami() // -> "I am a RedisObject"
    console.log User.find().whoami()        // -> "I am a User"
    

    At least the above test seems to pass.

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

Sidebar

Related Questions

I am building a Windows form application using .NET 3.5. I would like to
I am building a todo app using express framework on node server...I have an
I am using webmatrix and building node.js application. In that i want to pass
I am building a Node Express application using Jade, and I am confused about
I'm currently building a realtime application using Node. I'm using socket.io to power my
Alright, so I'm building an application based in Node.js and I am using mongoose
Okay so basically I am building an application for JavaScript development using Node. My
I'm building a node.js application with Mongoose and have a problem related to sorting
I am building an ASP.NET web application that will be deployed to a 4-node
I'm building an app in Backbone using Node as the backend. As part of

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.