Created
November 17, 2018 18:38
-
-
Save thinkphp/355dd4242b7f011c8fa03bbee9e2327c to your computer and use it in GitHub Desktop.
CoffeScript in Browser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"/> | |
<title>CoffeScript on browser</title> | |
</head> | |
<body> | |
<script type="text/coffeescript"> | |
class Animal | |
constructor: (@name) -> | |
move: (meters) -> | |
alert @name + " moved #{@meters}m." | |
class Snake extends Animal | |
move: -> | |
alert "Slithering..." | |
super 5 | |
class Horse extends Animal | |
move: -> | |
alert "Galloping..." | |
super 45 | |
sam = new Snake "Sammy the Python" | |
tom = new Horse "Tommy the Palamino" | |
sam.move() | |
tom.move() | |
gcd = (x, y) -> | |
if y is 0 then x else gcd y, x % y | |
alert gcd 10, 4 | |
</script> | |
<script src="https://cdn.rawgit.com/jashkenas/coffeescript/1.11.1/extras/coffee-script.js"> | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment