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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:40:11+00:00 2026-05-24T03:40:11+00:00

Most of the time (tutorials mainly), I have seen prototype used for methods. I’m

  • 0

Most of the time (tutorials mainly), I have seen “prototype” used for methods.

I’m pretty sure it can also be used for variables (perhaps the most useful for setting “default values”). Is there a reason it’s not often used for functions? Is it bad practice, or are there noticeable performance differences?

  • 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-24T03:40:12+00:00Added an answer on May 24, 2026 at 3:40 am

    Think about it the other way round: Why would you want to store an object’s attribute in its prototype?

    There’s two answers:

    1. Save memory. Defining methods on every instance would consume an awful amount, since technically each instance would have its own method. The cost is considerably lower for simple data types.
    2. Shared access. Instances may need to share access to a common attribute. However, this is not possible for simple data types, since those are not stored by reference.

    As gilly3 mentioned, 2. may just accidentally happen if you’re not absolutely sure what you’re doing. (Oh yes, it happened to me…)

    Best practice:

    • Methods go to the prototype
    • Attributes go to the instances, unless you need shared access (and the attribute is object-typed).

    [edit]

    • Shared access should be implemented using closures, not “class variables”

    [/edit]

    And yes, the performance of using prototype is slightly worse than the other way. BUT you should never try to optimize things like that, since the performance gain is almost unnoticeable, yet the readability and maintainability of your code may suffer significantly.

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

Sidebar

Related Questions

This time I have a more philosopical question. Most MVC tutorials/books seem to suggest
Most of time we represent concepts which can never be less than 0. For
Most of the time, I've seen release management handled as a defined process with
For a particular segment of Java code, I'd like to measure: Execution time (most
Spending most of my time in Visual Studio and using all the IDE tools,
I would like to hide the UISearchBar most of the time and only call
As I put together each asp.net page It's clear that most of the time
I've got 2 monitors, and most of the time I've got some reference material
I've got a php script. Most of the time the script returns html, which
When running PHP in CLI mode, most of the time (not always), the script

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.