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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:33:38+00:00 2026-05-31T07:33:38+00:00

How come one pattern works and the other doesnt? In the second code the

  • 0

How come one pattern works and the other doesnt? In the second code the link to the prototype is lost,is there any way of estabilishing the link to the prototype using the second pattern?Or am I doing it wrong?

This Works

function Robot() {
    this.weapons=5;
    this.lives=5;
}

Robot.prototype.fireWeapon=function(){alert('weapons fired');};

var a=new Robot();
a.fireWeapon();

This doesnt work

function Robot() {

    var weapons=5;
    var lives=10;

    return {
        weapons: weapons,
        lives : lives
    };
}

Robot.prototype.fireWeapon=function(){alert('weapons fired');};

var a=new Robot();
a.fireWeapon();
  • 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-31T07:33:39+00:00Added an answer on May 31, 2026 at 7:33 am

    That is because it in the second example you don’t have a Robot, you have an Object.

    By returning a new anonymous object, you override the expression that would be assigned to a by default, which is the Robot.

    Try this line in each and you will see:

    alert(a.constructor);
    

    For the first one, you will see Object and the second, you will see the Robot function.

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

Sidebar

Related Questions

I am building a Firefox extension and have come a long way. One of
I come across this pattern occasionally and I haven't found a terribly satisfactory way
This is a small doubt and something that shouldn't really come to one's mind.So
One problem that I come across regularly and yet don't have a solution to
One of the problems I have come across having complex tasks on the browser
The best one I have come up with so far is that a card
One of my team has recently come across an interesting glitch in the matrix.
Which one is better to use when it come to return value for example
This is one of the possible ways I come out: struct RetrieveKey { template
I've come across a tutorial (reputable one if I may add) where the closing

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.