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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:30:47+00:00 2026-05-25T14:30:47+00:00

Example: class Complex constructor: (@a, @b) -> conjugate: -> new Complex(@a, -@b) class ComplexSon

  • 0

Example:

  class Complex 
    constructor: (@a, @b) ->
    conjugate: -> new Complex(@a, -@b)

  class ComplexSon extends Complex
    constructor: (@a, @b) ->
      @c = 3.14
    magnitude: -> @a*@a + @b*@b

I have defined the following method:

  dumpMethods = (klass) ->
    Object.getOwnPropertyNames(klass.property).sort()

Test cases:

  dumpMethods(Complex) == ['conjugate', 'constructor']   
    # success

  dumpMethods(ComplexSon) == ['conjugate', 'constructor', 'magnitude'] 
    # fails, returns                      ['constructor', 'magnitude'] 

What is the correct definition of dumpMethods?

  • 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-25T14:30:48+00:00Added an answer on May 25, 2026 at 2:30 pm

    ban,

    Javascript (and consequently coffee script) use prototypal objects.

    I suggest you read about it because the matter is rather complex.

    Trying to summarize, each object has a prototype. The prototype is itself an object, has its own properties, and also has a prototype, and so on.

    The chain of prototypes actually defines the class hierarchy. So in you case, ComplexSon will have a prototype that is Complex, that will have a prototype that is Object itself, the root of all object hierarchies in javascript.

    When you call a method on an instance, javascript will search for that method on that instance, then in its prototype, then up on the chain. The first one found is the method it will execute.

    As in most programming languages, you can go “up” the hierarchy and see superclasses, but rarely you can go down cause it is rarely needed by the language interpreter itself. However there are some workarounds, like ones used by prototype, to know the subclasses of a given class, but AFAIK they are not in the lauage itself, most often they simply keeps track of defined classes.

    Regarding the methods, in your code you are looking at the properties of ComplexSon, that correctly consist of only two methods. The other one (coniugate) is not there cause it is reached via the prototype, you can list them all by recursively going up the prototype chain.

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

Sidebar

Related Questions

I have the following example class: Test.h: @interface Test : UIButton { NSString *value;
I have models (simplified example): class Group(models.Model): name = models.CharField(max_length = 32) class Person(models.Model):
Take the following class as an example: class Sometype { int someValue; public Sometype(int
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
I have reduced a complex schema to the following samples Students StudentID int, Name
Please consider this example class: [Serializable] public class SomeClass { private DateTime _SomeDateTime; public
If I have a class as follows class Example_Class { private: int x; int
What is the syntax for placing constraints on multiple types? The basic example: class
For example: Base class header file has: enum FOO { FOO_A, FOO_B, FOO_C, FOO_USERSTART
For example: public class A : A.B { public class B { } }

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.