8:30 – 4:30 ESSO
- Bronchitis. Urk.
- Backups, and some fixing of databases, as well as acknowledging all the alerts. We really need to turn some scripts off tomorrow.
- Showed Carla how the issue was really bad labeling of what the “1 of 4” items actually were.
- Javascript
- So this is how you define an inheritable class:
- Wow – this overwrites the value in the base parent Object, so that every instance of the superclass or subclass now say “foo”:
SubType.prototype.saySuperName = function(){ return "foo"; }; - This appears to be a good way to do inheritance:
//--------- SuperType definition ------------ function SuperType(name){ this.name = name; this.nickName = "None"; this.colors = ["red", "blue", "green"]; } SuperType.prototype.setNickname = function(nickName){ this.nickName = nickName; } SuperType.prototype.sayName = function(){ alert("Name = "+this.name+", Nickname = "+this.nickName); }; //--------- SubType definition ------------ function SubType(name, age){ SuperType.call(this, name); this.age = age; } SubType.prototype = new SuperType(); SubType.prototype.sayAge = function(){ if(this.nickName == "None"){ alert(this.name+" is "+this.age+" years old"); }else{ alert(this.nickName+" is "+this.age+" years old"); } }; //----------- sequential code -------------------- var instance1 = new SubType("Nicholas", 29); instance1.setNickname("Nick"); instance1.colors.push("black"); alert(instance1.name+"'s colors are: "+instance1.colors); //"red,blue,green,black" instance1.sayName(); //"Nicholas"; instance1.sayAge(); //29 var instance2 = new SubType("Greg", 27); alert(instance2.name+"'s colors are: "+instance2.colors); //"red,blue,green" instance2.sayName(); //"Greg"; instance2.sayAge(); //27
