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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:40:39+00:00 2026-05-28T20:40:39+00:00

in javascript there are so many different ways to set up a method for

  • 0

in javascript there are so many different ways to set up a method for something such as a button click event.

for example say you have retreived an input element ‘button’

function MyForm(){
   //anonymous method
   button.click = function(){ //work };


   //private method
   var handleClick = function () { // work };
   button.click = handleClick;

   //public method
   button.click = outerClickHandle;


}

//public
function outerClickHandle(){
    // work
}

//prototype
MyForm.prototype.outerClickProto(){
   //work
}

there are of course some of the more obvious answers such as encapsulation when desired. And with the prototype you don’t have to recreate that function each time which is good for performance, but as for anonymous methods, other than being a nice way, or flow of writing the script, what is good and bad?

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

    The main advantage I find is that because it’s declared inline, the anonymous function has access to all the current local variables within scope which can vastly simplify your code in some circumstances. A classic example is with setTimeout() where you want it to operate using variables defined in the scope above.

    Of course, an anonymous function also doesn’t interfere with whatever namespace you’re in (global, local within the function, etc…) since it doesn’t need a name.

    A disadvantage of using an anonymous function with an addEventListener(type, fn) event handler is that you can’t remove just that event listener because you don’t have a handle on the function.

    Another disadvantage of anonymous functions is that a new function is created every time the code that uses it runs, which in some cases makes no difference at all, but in other cases may be something to consider for performance reasons (e.g., if doing things in a loop)

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

Sidebar

Related Questions

There are so many different ways to include JavaScript in a html page. I
There seem to be many different ways of doing OO in JavaScript. I like:
There have been many JVM languages in the recent few years including Javascript, Python,
There are so many different tools concerning JavaScript. What are the best tools to
In my store there many items have different options like size or color. The
I'm making an input that looks like this: There are many different ways to
In the JavaScript the same thing you can do in many different ways. Consider
I'm new at javascript and while there are many more complex solutions, I don't
There are many "standards" for the JSON content type: application/json application/x-javascript text/javascript text/x-javascript text/x-json
There was a post this morning asking about how many people disable JavaScript. Then

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.