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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:46:30+00:00 2026-05-22T17:46:30+00:00

I was playing around with function expressions and trying to get my head round

  • 0

I was playing around with function expressions and trying to get my head round some stuff.This is the code I wrote.

This works

var sum=function(arg1,arg2){
    return(function(){alert(arg1*arg2)})
}

document.getElementById('button_1').onclick=sum(3,2);

This doesnt,I know it doesnt even look right.But Im just trying to understand the reason behind the error that was being displayed here.It first displayed the alert box with 6 then an error message “Not Implemented”,this is in IE6.

var sum=function(arg1,arg2){
    alert(arg1*arg2);
}

document.getElementById('button_1').onclick=sum(3,2);

If you guys think this question doesn’t require an answer please let me know,I will delete it.

Thanks

  • 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-22T17:46:31+00:00Added an answer on May 22, 2026 at 5:46 pm

    In the second example your sum variable doesn’t return a function pointer. The onclick event must be assigned to a function pointer. So in this second example you are directly invoking the sum function by passing it two arguments and because this function doesn’t return anything (it simply alerts) it doesn’t work. To make it work with the second example you need:

    document.getElementById('button_1').onclick = sum;
    

    But once the button is clicked it will pass a single argument to this sum function which represents the event.

    In the first example you invoke the sum function by passing it two arguments but this invocation simply returns another function which is then assigned to the onclick event.

    I guess you want this though:

    document.getElementById('button_1').onclick = function() { sum(3,2); };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been playing around trying to get a function that will sort a selection
While playing around with regexps in Scala I wrote something like this: scala> val
After playing around with haskell a bit I stumbled over this function: Prelude Data.Maclaurin>
So I've been playing around with the replace function (method?) in js. $get('msgBar').replace(/+/g,' ');
I am playing around with lisp's format function, but I have hit a snag
Just playing around with the now released Silverlight 2.0. I'm trying to put a
I was playing around with my own Sudoku solver and was looking for some
I'm playing around with beginner Haskell, and I wanted to write an average function.
So I was playing around with Haskell today, thinking about autogeneration of function definitions
I am playing around with a code example i found here about 'tree menu'

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.