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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:44:14+00:00 2026-05-25T16:44:14+00:00

Q1) How is this possible?! function employer(name) { this.name = name;}; var fred =

  • 0

Q1) How is this possible?!

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

var fred = new employer('Fred');

Isn’t employer a function rather than a class?

Q2) What does

employer.prototype

signify?

and finally

Q3) How does this work?

employer.prototype.salary = null;
fred.salary = 2000;

Can someone please give simple explanation? Please 🙂

  • 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-25T16:44:14+00:00Added an answer on May 25, 2026 at 4:44 pm

    As you asked for a simple explanation, here we go:

    Q1) This is possible because JavaScript functions are first-class (i.e. they are objects, and you can create new objects).

    Q2) A prototype is an object from which other objects inherit properties. Properties of an objects prototype will be available to all instances of that object.

    Q3) This means that all instances of employer will have a property salary with the value null. The instance of employer called fred simply overrides that initial null value with 2000. It’s the same salary property though (when you use a property, the scope chain is searched until a match is found. In this case, a match is found on the object prototype).

    Quick example:

    function employer(name) { this.name = name;};
    employer.prototype.salary = 1000;
    
    var fred = new employer('Fred');
    var jim = new employer('Jim');
    
    console.log(fred.salary) //Prints 1000 because employer.prototype.salary == 1000
    fred.salary = 2000;
    console.log(fred.salary) //Prints 2000 because fred's salary has been changed
    console.log(jim.salary) //Prints 1000 because jim's salary is still referencing the prototype
    
    fred.age = 30;
    console.log(fred.age) //Prints 30
    console.log(jim.age) //Prints undefined (age is a property of fred, not employer.prototype
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is something like this possible: function FooClass() { var barsArray=new Array(); var index=0; function
Is it possible to call functions from class like this: $class = new class;
Is this possible given the button_to_remote function seems to be defined as a Prototype
Is this a possible function? I need to check if a variable is existent
Is this possible? example: $('a.change').click(function(){ //code to change p tag to h5 tag });
Is this possible? I am creating a single base factory function to drive factories
I want my Makefile to be as simple as possible and still function. This
Is it possible to do something like this? public function something() { $thisMethodName =
$(#tab1).click(function(){ loadTab(1); $('div.HOMEtabdiv ul.HOMEtabs a').removeClass('selected'); $(this).addClass('selected'); }); Would it be possible to make the
Is this possible? Code: $('#goRightBtn').click(function() { Random code here }; I have a button,

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.