Self in your browser?

Jan Bottorff janb at pmatrix.com
Wed Nov 10 00:32:47 UTC 1999


Is everybody aware that JavaScript (ECMAScript?) could be classed as a
language derived from Self. It has object prototypes that work like you'de
expect. If you look at the ECMAScript spec, the influences of Self are
obvious. I personally rejected JavaScript as a significant language until I
read the spec and was really surprised what advanced concepts it had. 

As far as I know, the implementations of JavaScript have been source code
interpreters, so run REAL slow. The standard base objects defined in your
typical browser implementation are rather less than rich (or maybe it's
just a development environment issue, would Self be much fun if all you had
was a text editor?). 

A high performance implementation, with a rich set of base objects might
make a real interesting environment. A quick example that demonstrates
object inheritance:

<SCRIPT LANGUAGE="javascript"> 

  // define a prototype object kind
  function kindA() {
    this.prop1 = "prop1 in KindA";
    this.prop2 = "prop2 in KindA";
  }

  // create two objects from the prototype kindA
  AGlobal = new kindA;
  BGlobal = new kindA;

  // update a property on one of the instances
  AGlobal.prop1 = "updated prop1";
 
  // show how each object instance is unique
  document.writeln(AGlobal.prop1);
  document.writeln(BGlobal.prop1);

  // add a new property to the prototype object of both AGlobal and BGlobal
  kindA.prototype.prop3 = "new prop3";

  // show how both objects now have a new property, because they inherit
from a common parent object
  document.writeln(AGlobal.prop3);
  document.writeln(BGlobal.prop3);

</SCRIPT> 

- Jan





More information about the Squeak-dev mailing list