1/* Copyright JS Foundation and other contributors, http://js.foundation 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16class Animal { 17 constructor (name) { 18 this.name = name; 19 } 20 21 hello () { 22 return "Hello I am " + this.name; 23 } 24 25 static speak () { 26 return "Animals roar."; 27 } 28 29 static explain () { 30 return "I can walk,"; 31 } 32 33 whoAmI () { 34 return "I am an Animal."; 35 } 36 37 breath () { 38 return "I am breathing."; 39 } 40 41 get myName () { 42 return this.name; 43 } 44 45 set rename (name) { 46 this.name = name; 47 } 48} 49 50class Dog extends Animal { 51 constructor (name, barks) { 52 super (name); 53 this.barks = barks; 54 } 55 56 hello () { 57 return super.hello () + " and I can " + (this.barks ? "bark" : "not bark"); 58 } 59 60 whoAmI () { 61 return "I am a Dog."; 62 } 63 64 static speak () { 65 return "Dogs bark."; 66 } 67 68 static explain () { 69 return super.explain () + " jump,"; 70 } 71 72 bark () { 73 return this.barks ? "Woof" : "----"; 74 } 75} 76 77class Doge extends Dog { 78 constructor (name, barks, awesomeness) { 79 super (name, barks); 80 this.awesomeness = awesomeness; 81 } 82 83 hello () { 84 return super.hello () + " and I'm " + (this.awesomeness > 9000 ? "super awesome" : "awesome") + "."; 85 } 86 87 whoAmI ( ) { 88 return "I am a Doge."; 89 } 90 91 static speak () { 92 return "Doges wow."; 93 } 94 95 static explain () { 96 return super.explain () + " dance."; 97 } 98} 99 100var doge = new Doge ("doggoe", true, 10000); 101assert (doge.name === "doggoe"); 102doge.rename = "doggo"; 103assert (doge.myName === "doggo"); 104assert (doge.barks === true); 105assert (doge.awesomeness === 10000); 106assert (doge.hello () === "Hello I am doggo and I can bark and I'm super awesome."); 107assert (doge.whoAmI () === "I am a Doge."); 108assert (doge.breath () === "I am breathing."); 109assert (doge.bark () === "Woof"); 110assert (Doge.speak () === "Doges wow."); 111assert (Doge.explain () === "I can walk, jump, dance."); 112assert (doge instanceof Animal); 113assert (doge instanceof Dog); 114assert (doge instanceof Doge); 115assert (Dog.prototype.constructor === Dog) 116assert (Doge.prototype.constructor === Doge) 117