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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:16:43+00:00 2026-05-23T02:16:43+00:00

So if I was to create an object literal like this.. var person1 =

  • 0

So if I was to create an object literal like this..

var person1 = {

  age : 28,
  name : 'Pete'  }

Then I add a function to the object…

  person1.sayHelloName = function(){

     return 'Hello ' + this.name;

  };

  alert(person1.sayHelloName());

Im wondering where the ‘prototype’ keyword comes into all this. I cant add a prototype to an object (only to a function constructor) so would I be able/have to use the prototype in this scenario.

  • 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-23T02:16:43+00:00Added an answer on May 23, 2026 at 2:16 am

    You can’t use the prototype in this way because, like you say, it’s used to add properties to a constructor which must be defined with the function() keyword. What you are doing in your example is extending the person1 object, but that object is just a single variable and not an instantiable class. Meaning you can’t “create” another person1 using the new keyword, whereas you could if it were an instance of a defined class.

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

Sidebar

Related Questions

Is it possible to creat an object literal on the fly? Like this: var
I need to create an array of object literals like this: var myColumnDefs =
I want to create JSON object using tow query in PHP , Then retrieve
I know you can create literal objects with subobjects and functions: var obj =
if (typeof Object.create !== 'function') { Object.create = function (o) { function F() {
I have a tab panel like this: var tab1 = { id: 'section1', title:
I have a tab panel like this: var tab1 = { id: 'section1', title:
I need to create the following JavaScript object literal in C# code, as a
I created an object literal in JS, but wanna to access a property without
I want to dynamically create object of HtmlDivElement in my jsf managed bean and

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.