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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:44:32+00:00 2026-06-18T22:44:32+00:00

When should I use first notation: var object = { a: function() { //

  • 0

When should I use first notation:

var object = {
    a: function() {
        // object.a method body
    },
    b: function() {
        // object.b method body
    },
    c: function() {
        // object.c method body
    },
};

and when the second one?

function Class() {};

Class.prototype.a = function() {
    // object.a method body
};

Class.prototype.b = function() {
    // object.b method body
};

Class.prototype.c = function() {
    // object.c method body
};

var object = new Class();
  • 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-18T22:44:33+00:00Added an answer on June 18, 2026 at 10:44 pm

    The main advantage is that the functions are shared by all instances in second case, which makes the objects lighter. It explicitly defines the objects as instances of what is conceptually a class.

    But the correct syntax is

    function MyClass(){
    }
    MyClass.prototype.a = function(){
    };
    ...
    var o = new MyClass();
    

    It also allows you to define an inheritance chain :

    function OtherClass(){
    }
    OtherClass.prototype = new MyClass(); // makes OtherClass extend MyClass
    OtherClass.prototype.b = function(){
    };
    ...
    var o2 = new OtherClass();
    

    o2 has the functions of both OtherClass and MyClass.

    The MDN gives more details in its Introduction to Object-Oriented JavaScript.

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

Sidebar

Related Questions

I have two C files (first file need another one). I should use #include
/competitions/1/clubs/5/players /players/search?club_id=5 /players?club_id=5 When should I use a first-class URL for a resource, and
What should I use: /findby/name/{first}_{last} /findby/name/{first}-{last} /findby/name/{first};{last} /findby/name/first/{first}/last/{last} etc. The URI represents a Person
I'm wondering if I should use OpenId for my website. My first exposure to
I was just curious, why should we use reflection in the first place? //
First I read this article I think I should use "copy" in my programe.
I'm evaluating some technologies for a new Web Application. Which should use EF5 and
I figure I should use 'Aggregate' but apparently I am getting it wrong First
I've read I should use money , but in todays fast paced world maybe
Why sometimes I should use block and other times &block inside functions that accept

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.