HELP! * YELLOW=global GREY=local Global HTML version of Foils prepared 21 February 97

Foil 59 The Function Object and Event Handlers

From Feb 17/19 Delivered Lecture for Course CPS616 -- aJavaScript Language Objects and Frames CPS616 spring 1997 -- Feb 17 and 19 1997. by Geoffrey Fox * Important Information in IMAGE
Secs 96.4
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 dynamic event handlers which as described 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 Fri Feb 21 1997