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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:13:55+00:00 2026-05-30T23:13:55+00:00

I am reading this: http://killdream.github.com/blog/2011/10/understanding-javascript-oop/index.html and i’ve encountered some code that i can’t understand:

  • 0

I am reading this: http://killdream.github.com/blog/2011/10/understanding-javascript-oop/index.html

and i’ve encountered some code that i can’t understand:

function Person(first_name, last_name) {
    this.first_name = first_name
    this.last_name  = last_name
}

// Defines the `name' getter/setter
Object.defineProperty(Person.prototype, 'name', { get: get_full_name
                                                , set: set_full_name
                                                , configurable: true
                                                , enumerable:   true })

Why is he using Object.defineProperty on Person.prototype and not simply on Person?
Why not simply include name in the definition or make Person.name = bla...?

(EDIT: SOLVED)
also, why am i seeing this endless loop of prototype reference??

why am i seeing this endless loop of prototype reference?

  • 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-30T23:13:56+00:00Added an answer on May 30, 2026 at 11:13 pm

    If he’d use Object.defineProperty on Person then you’d define a property on that function and not on the instances you create with new Person.

    I.e. given Object.defineProperty(Person, ...) you were able to do

    Person.name = 'foo';
    

    but that would not really help in this situation.

    On the other hand, properties of the prototype are shared by all instances and therefore it makes sense to define this property on the prototype.

    Here Person is a constructor function which is supposed to be called with the new keyword. It probably will help to read about what new is doing, in order to understand why Person.prototype has to be extended.
    The gist: When called with new, inside the function, this will refer to an empty object inheriting from Person.prototype.

    Regarding the second part: Each function has a prototype property, and each prototype has a constructor property referring to its “parent” function. Thus you have a self referencing structure:

    Person.prototype.constructor === Person;
    

    What you showed is not the prototype chain, which can be revealed by inspecting __proto__.

    I could simulate the same with:

    var a = {};
    a.b = {a: a};
    

    and I could access a.b.a.b.a.b.a.b.a.b.a indefinitely.

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

Sidebar

Related Questions

I was reading this article on Coding Horror: http://www.codinghorror.com/blog/2008/04/setting-up-subversion-on-windows.html I went to the downloads
I was reading this blog( http://googlepublicpolicy.blogspot.com/2009/06/https-security-for-web-applications.html ) posted by google on not enabling HTTPS
I am reading this E.F. Team Blog's this series http://blogs.msdn.com/b/adonet/archive/2011/01/27/using-dbcontext-in-ef-feature-ctp5-part-1-introduction-and-model.aspx At many places i
I am reading this: http://www.panoramio.com/api/widget/api.html#photo-widget to build a JavaScript photo widget. Under Request ->
just was reading this article http://highscalability.com/blog/2010/3/23/digg-4000-performance-increase-by-sorting-in-php-rather-than.html And found this nice article http://wiki.apache.org/cassandra/DataModel I just
I was reading through this article: http://aws.typepad.com/aws/2008/12/running-everything-on-aws-soocialcom.html And I was wondering if this was
Just finished reading this blog post: http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/ In it, the author argues the case
I was reading this http://developer.android.com/guide/topics/wireless/bluetooth.html#QueryingPairedDevices which is allot of help on how to pair,connect
i am reading this page http://www.cplusplus.com/doc/tutorial/exceptions.html it says if i write function() throw(); no
I was reading this: http://www.openfeint.com/ofdeveloper/index.php/kb/article/000089 , and it seemed to make out that 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.