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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:27:19+00:00 2026-06-12T20:27:19+00:00

What on earth is going on here? How can the Daughter -class contain data

  • 0

What on earth is going on here?
How can the Daughter-class contain data that’s been set in Brother, and how should I make sure that data set in sibling classes doesn’t interfere with eachother?

class Parent 
  data: {}

class Child extends Parent
  age: 10

Son = new Child
Son.data.name = "John Doe"

Daughter = new Child
console.log Daughter.data # => { name: 'John Doe' }
  • 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-12T20:27:20+00:00Added an answer on June 12, 2026 at 8:27 pm

    If you take your CS code and put it in the side-by-side editor on CoffeeScript’s site (http://coffeescript.org/), you’ll see that data is on the prototype of the Parent “class”. Think of that prototype being the template for new functions (classes) that you create. That prototype either contains other functions or it contains variables available to all instances (like an OO static variable).

    You’re adding name to a “static” variable data. It will then be available to all instances that “derive” from Parent.

    I’m not sure of the inner workings that go on there, but coming from an OO world, that’s how I interpret it. I hope this helps.

    GENERATED CODE VIA COFFEESCRIPT’S SITE

    var Child, Daughter, Parent, Son,
      __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; };
    
    Parent = (function() {
    
      function Parent() {}
    
      Parent.prototype.data = {};
    
      return Parent;
    
    })();
    
    Child = (function(_super) {
    
      __extends(Child, _super);
    
      function Child() {
        return Child.__super__.constructor.apply(this, arguments);
      }
    
      Child.prototype.age = 10;
    
      return Child;
    
    })(Parent);
    
    Son = new Child;
    
    Son.data.name = "John Doe";
    
    Daughter = new Child;
    
    alert(Daughter.data.name);
    

    UPDATE
    Just noticed that the CS side-by-side window has a link feature. Here’s a link to the side-by-side code.

    UPDATE #2

    In response to your question in the comments, I’m not sure exactly what you want to do, but you could do something like this:

    class Parent 
      #data: {}
    
    class Child extends Parent
      constructor: (@name) ->
      age: 10
      sayHi: -> alert "Hi " + @name
    
    
    Son = new Child "John Doe"
    
    Daughter = new Child "Sarah Jane"
    
    Son.sayHi()
    Daughter.sayHi()
    

    Perhaps keep the name variable (or the entire data variable) at the parent level and set it via a constructor and access it via a parent function.

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

Sidebar

Related Questions

Now that Google Earth has been released for Android 2.1, does anyone know what,
How on earth do I make this work? I have a database with 3
I've been asked to add Google Earth images to a desktop app (civil engineering
How can i create .KMZ (google earth file format) programmatically? .KMZ contains a .KML
I am attempting to install libxml2 so that I can setup the python bindings
I have a Core Data importer that loops through data, and ignores duplicate records
I'm learning Java, and now that I'm over the packages hump, things are going
We've been having a problem with a mass mailer component that I wrote for
I can't understand how x and y are the same list. I've been trying
Here's the code after which I set a breakpoint (I added the casts to

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.