Skip to content

Instantly share code, notes, and snippets.

@Reasoning-Technology
Created August 20, 2018 13:09
Show Gist options
  • Save Reasoning-Technology/d1d0e3d7aa64787bf390e4b3dcf2be73 to your computer and use it in GitHub Desktop.
Save Reasoning-Technology/d1d0e3d7aa64787bf390e4b3dcf2be73 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>test_box_0</title>
<script src="date_stamp.js"></script>
<script src="test_rabbit.js"></script>
</head>
<body>
<script>date_stamp();</script>
<script>
let rabbit = new Rabbit("White Rabbit");
rabbit.run(5);
this.hide();
</script>
</body>
</html>
class Animal {
constructor(name) {
this.speed = 0;
this.name = name;
}
run(speed) {
this.speed += speed;
alert(`${this.name} runs with speed ${this.speed}.`);
}
stop() {
this.speed = 0;
alert(`${this.name} stopped.`);
}
}
class Rabbit extends Animal {
hide() {
alert(`${this.name} hides!`);
}
stop() {
super.stop(); // call parent stop
this.hide(); // and then hide
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment