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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:09:10+00:00 2026-06-04T11:09:10+00:00

Suppose I create an object in javascript. var myObject = {}; What is the

  • 0

Suppose I create an object in javascript.

var myObject = {};

What is the difference between…

myObject.someFunc = function(){...}; 

and

myObject.prototype.someFunc = function(){...} 

in javascript?

I am having trouble understanding the difference or if there is a difference and how and when to use either of these syntaxes.

It seems when I code something like this that there really is no difference.

I am looking for both a client side (browser) and server side (like node.js) answers.

I want to code properly and accurately and this is really bothering me.

  • 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-04T11:09:12+00:00Added an answer on June 4, 2026 at 11:09 am

    In this case:

    var myObject = {};
    myObject.someFunc = function(){...}; 
    

    All you’re doing is creating a plain object, which happens to have a property which is a reference to a function. This is often done just for name spacing, i.e. to group a whole load of functions in one place under a common object.

    Note however that var myObject = {} doesn’t actually have a prototype so your second example is impossible.

    For an object to have a prototype it must be the result of a constructor function, i.e.

    function MyObject() {
        ...
    }
    
    MyObject.prototype.someFunc = function() { }
    
    var myObject = new MyObject();
    // myObject.someFunc can now be used
    

    The prototype is a property of the constructor function – not of any instance of that class.

    If you put the function on the prototype only one instance of the function object exists and will be shared by all instances of the class. This is more memory efficient that having a copy on each instance.

    All of this applies regardless of whether the code is in a browser or on a server – it’s still the same language.

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

Sidebar

Related Questions

Suppose I create a custom object/javascript class (airquotes) as follows: // Constructor function CustomObject(stringParam)
Let's suppose I want to create a javascript class/object/function which have a method that
Suppose we have a class. We create an object from the class and when
Suppose I have a user defined type: CREATE OR REPLACE TYPE TEST_TYPE AS OBJECT
This is about inheritance in JavaScript. Suppose I create a constructor Bird(), and another
Suppose I have the following: using(var ctx = DataContextFactory.Create(0)) { ... Some code ...
Consider the following Javascript function (1): function setData(domElement) { domElement.myDataProperty = { 'suppose': 'this',
Suppose you create a generic Object variable and assign it to a specific instance.
Suppose I create a new thread and passes an object to it. How to
There is a logic and properties used to create certain object. That logic is

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.