Accidental Ideas #1
I was messing around with some OO JavaScript just sort of keeping my mind loose for a big test I have to take tomorrow, when from the haze of studying I accidentally did this:
<script> function obj(){ //the base object, on which all other objects depend to exist this.size=0; //These are just arbitrary traits this.idea=1; } function plane(x,y){ //When this object comes into 'existence' by being instantiated it requires an obj. It has it's own qualities, but it doesn't exist without existing as a descendent of obj. this.width=x; this.length=y; } function box(x,y){ //this object is comprised of 6 planes, each of which have an associated obj. It, however, doesn't have an obj. It does not exist in and of itself, it only exists by virtue of the things that are defining it. There's a metaphor here, is what I'm saying. I'd make it, but yours will be better. this.sides=new Array(6); for(i=0;i<this.sides.length;i++){ this.sides[i]=new plane(x,y); } // alert("ss"); } plane.prototype=new obj(); var t=new box(3,4); alert(t.sides[0].idea); //See the sides all exist in that they have the traits of existing(the idea) alert(t.idea); //But the box object itself doesn't exist\lacks the traits of existence(the idea) </script>
Truer now, than when it was spoken.










