HELP! * GREY=local LOCAL HTML version of Foils prepared 15 January 1997

Foil 57 The Function Object and Event Handlers

From JavaScript Tutorial for CPS616 Technologies of the Information Age 1997 Basic Information Track of CPS -- Spring Semester 97. by Geoffrey C. Fox * Important Information in IMAGE

One can define a string of JavaScript to be compiled as a function with syntax
Target = new Function( [arg1,...argn], functionBody)
where the optional arg1,...argn are arguments for formal function defined in functionBody
Target is either the name of a variable or a property of an existing object or an event handler such as window.onerror
var setBGcolor = new Function("document.bgColor='antiquewhite'");
so you can now execute setBGcolor() where the function can be changed at any time with another setBGcolor = new Function("document.bgColor='pink'");
One can define event handlers which MUST be lower case and MUST have no arguments
  • window.onfocus = setBGcolor;
Note like eval, functionBody can be JavaScript constructed dynamically as in
  • var dynamic = 'bgcolor';
  • Function("document." + dynamic + "='antiquewhite'");



Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Feb 19 1997