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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:20:23+00:00 2026-06-16T07:20:23+00:00

I am a little perplexed about what is going on with my code, here

  • 0

I am a little perplexed about what is going on with my code, here is what I have so far:

function Person(name) {
    this.name = name;
}

Person.prototype.getName = this.name;
Person.prototype.displayName = function() {
    return this.name;
}


var Sethen = new Person("Sethen");

console.log(Sethen.getName);
console.log(Sethen.displayName());

I am curious as to why getName doesn’t give me the this.name value and only logs blank, while the displayName method gives me the correct value. getName is a property of my prototype object, so my thought process was that I could grab it like this.

Why does getName not log the value of Sethen? How would I go about grabbing that information like a regular property? Must I use a method?

  • 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-16T07:20:24+00:00Added an answer on June 16, 2026 at 7:20 am

    Because the value of this isn’t what you think it is when that code is run. this is probably equal to the global object (i.e. window).

    Since you’re calling displayName and setting the context by prefixing it with an instance of the Person object, this is set correctly inside of the function and you get the person’s name out.

    Of course, you could always access the name property directly (Sethen.name).

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

Sidebar

Related Questions

Little question about Ruby error handling. I have some code that roughly resembles the
I am a little perplexed here with the actions of WPF. I can change
Little trouble in using css, in the below code, i have used odd and
A little help here to figure out what error to run this piece of
A little bit about the code; what I'm trying to do is turning a
Little question here, i have a sprite image that contain icons with normal and
Little extended question is why jQuery do jQuery.fn = jQuery.prototype = { init: function()
little stuck on this jquery. I have a banner above my nav bar, which
This should work, so I'm really perplexed about why it's not working. I'm checking
Little help here: I am uploading my site following the instructions on this link

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.