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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:30:35+00:00 2026-06-11T17:30:35+00:00

Why this… class Person name: initial name constructor: (@name) -> class User extends Person

  • 0

Why this…

class Person
    name: "initial name"

    constructor: (@name) ->


class User extends Person
    password: "initial password"


f = new User "Felds"

console.log f
console.log "my name is '#{f.name}' and my password is '#{f.password}'"

b = new User "Bob"
b.password = "bob's password"

console.log b

… when run through coffee -p test.coffee | node outputs this?

{ name: 'Felds' }
my name is 'Felds' and my password is 'initial password'
{ name: 'Bob', password: 'bob\'s password' }

Why doesn’t the password property show on console.log f ? Where is it stored and how is it retrieved?

  • 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-11T17:30:36+00:00Added an answer on June 11, 2026 at 5:30 pm

    The 'initial password' value is stored in Person.prototype.password. Person.prototype is an object with all the common attributes shared between Person instances. When you access aPersonInstance.password, the password property is first looked up in the aPersonInstance object; if it’s not found there it will be looked up in its prototype, and then in its prototype’s prototype and so on.

    console.log f will not show f‘s prototype properties, only the properties stored in f themselves (also known as f‘s own properties). When you assign Bob’s password with b.password = 'bob\'s password' you’re creating a new password property in b itself, which will now be the value of accessing b.password, even though b‘s prototype still has the 'initial password' value. I hope that made some sense =P

    By storing 'initial password' in the prototype you’re sharing that value between all Person instances as a kind of default value. This is perfectly fine to do with strings or other primitive (immutable) types; but you have to take special care if you’re going to do it with arrays or other mutable objects, because the same object will be shared between all the class’ instances, and if one of them modifies it, e.g. @someArray.push 5, all the other ones are going to see it. In those cases, it’s usually preferable to initialize the attribute in the class constructor, like @someArray = [], to guarantee that each instance will have a different array/object attribute.

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

Sidebar

Related Questions

I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
This question is about WordPress cms. How to create a new admin user with
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
I want to run this <!-- This will remove the tag --> <xsl:template name=remove-html>
Why does the Android system throw this Exception? 05-18 12:33:44.169 W/System.err( 8230): java.io.IOException: Is
An Arabic name shall be sent via SOAP. The name is encoded like this:
This is my code: Stopwatch timer = new Stopwatch(); timer.Start(); while (timer.ElapsedMilliseconds < 3000)
This code is rejected by (at least) MSVC, ICC, and GCC: class A {
This is my code: OleDbConnection connection = new OleDbConnection( Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\\Offline.accdb;Persist Security Info=False); connection.Open();
This is my current code: journey.path[x].marker = new OpenLayers.Marker(journey.path[x].curpoint,journey.path[x].markerIcon); journey.path[x].marker.events.register('click', journey.path[x].marker, function(){alert('test');}); layer_device_markers.addMarker(journey.path[x].marker); The

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.