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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:01:12+00:00 2026-05-15T20:01:12+00:00

While writing javascript, one can define a method in 3 different ways. 1] A

  • 0

While writing javascript, one can define a method in 3 different ways.

1] A function in global namespace

function doSomething();

2] A function that is member of a function

function Clazz() {}
Clazz.doSomething = function(){};

3] A function that is memeber of the instance of function

function Clazz() {}
Clazz.prototype.doSomething = function(){};

Depending upon the code organization, one can choose one of the above methods over others.

But purely from performance standpoint which is the most efficient one? (especially between 1 and 2)

Will your answer be different if doSomething has arguments?

  • 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-15T20:01:13+00:00Added an answer on May 15, 2026 at 8:01 pm

    From a pure performance POV, 1 should be the fastest. The reason being that it would require less work to setup the scope chain & execution context. Also if you access any global variables from within the function, the resolution will be fastest with 1, again simply because of the depth of scope chain.
    As a general rule further up (near to the global) an object is in the scope, the faster it is. for the same reason accessing property a.b will be faster than accessing a.b.c

    The performance gain might not be too much in case of a simple function call, however it can mount up if say you call the function n a loop.

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

Sidebar

Related Questions

While writing an encryption method in JavaScript, I came to wondering what character encoding
I am writing one function on Javascript which needs to address all the anynymous
While writing a Javascript inheritance function some time ago I noticed some very strange
One of the reasons that I tend to dread writing Javascript for anything other
While writing code in a file that would comprise of PHP, HTML, CSS &
While writing a card shuffling algorithm I realized that there are 52! ~= 2^225
While writing a .jsp file, can i include all the html5 tags in it
Sometimes while writing Java in Eclipse, I write code that generates warnings. A common
While writing JavaScript code, I Separate each code block with <script> tags <script type=text/javascript>
I'm writing a utility that takes in a .resx file and creates a javascript

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.