Skip to content

Instantly share code, notes, and snippets.

@thinkphp
Created November 17, 2018 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkphp/355dd4242b7f011c8fa03bbee9e2327c to your computer and use it in GitHub Desktop.
Save thinkphp/355dd4242b7f011c8fa03bbee9e2327c to your computer and use it in GitHub Desktop.
CoffeScript in Browser
<!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