Basic HTML version of Foils prepared 23 June 1997

Foil 68 prototype Property

From JavaScript Tutorial for Certificate Course UC Web applications Certificate -- Summer 97. by Geoffrey C. Fox, Tom Scavo


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

in Table To:


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 Apr 1 1998