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

Foil 68 prototype Property

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

This allows you to dynamically change object definitions
We used function(constructor)
  • function car(make,model) { // An Example
  • this.make = make;
  • this.color = 'red';
  • this.model = model; }
  • mycar = new car("Ford","Explorer");
Suppose we wanted to add a new property 4wheelstatus
  • car.prototype.4wheelstatus = false;
  • mycar.4wheelstatus = true;
We can add methods with
  • function repaint(newcolor) {
    • this.color = newcolor; }
  • car.prototype.repaint =repaint;
We can avoid repainting mycar by assigning
mycar.repaint = specialrepaint;
  • function specialrepaint(newcolor) {}



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 Sat May 24 1997