diff --git a/index.html b/index.html index 1fa100d2..67f4f5a6 100644 --- a/index.html +++ b/index.html @@ -127,7 +127,7 @@ opposite = true= -42 if opposite # Functions: -square = (x) ->= (x) -> x * x +square = (x) -> x * x # Arrays: list = [1, 2, 3, 4, 5] @@ -136,10 +136,10 @@ list = [1, = root: Math.sqrt square: square - cube: (x) ->: (x) -> x * square x + cube: (x) -> x * square x # Splats: -race = (winner, runners...) ->= (winner, runners...) -> +race = (winner, runners...) -> print winner, runners # Existence: @@ -466,8 +466,8 @@ Expressions an arrow, and the function body. The empty function looks like this: ->
-square = (x) ->= (x) -> x * x -cube = (x) ->= (x) -> square(x) * x +square = (x) -> x * x +cube = (x) -> square(x) * xvar cube, square; square = function(x) { return x * x; @@ -486,7 +486,7 @@ cube = function(x) { Functions may also have default values for arguments. Override the default value by passing a non-null argument. -fill = (container, liquid = "coffee") ->= (container, liquid = "coffee") -> +fill = (container, liquid = "coffee") -> "Filling the #{container} with #{liquid}..." @@ -595,7 +595,7 @@ log object.class var yourself.outer = 1 -changeNumbers = ->= -> +changeNumbers = -> inner = -1 outer = 10 inner = changeNumbers() @@ -696,7 +696,7 @@ options || (options =gold = silver = rest = "unknown" -awardMedals = (first, second, others...) ->= (first, second, others...) -> +awardMedals = (first, second, others...) -> gold = first silver = second rest = others @@ -986,7 +986,7 @@ numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; pushed down into each possible branch of execution in the function below. -grade = (student) ->= (student) -> +quick access to an object's prototype; and super() is converted into a call against the immediate ancestor's method of the same name. -grade = (student) -> if student.excellentWork "A+" else if student.okayStuff @@ -1267,18 +1267,18 @@ zip = typeof lottery.d Constructor functions are named, to better support helpful stack traces.class Animal - constructor: (@name) ->: (@name) -> + constructor: (@name) -> - move: (meters) ->: (meters) -> + move: (meters) -> alert @name + " moved #{meters}m." -class Snake extends Animal - move: ->: -> +class Snake extends Animal + move: -> alert "Slithering..." super 5 -class Horse extends Animal - move: ->: -> +class Horse extends Animal + move: -> alert "Galloping..." super 45 @@ -1387,7 +1387,7 @@ tom.move();;'>runString::dasherize = ->= -> +String::dasherize = -> this.replace /_/g, "-"String.prototype.dasherize = function() { @@ -1433,7 +1433,7 @@ _ref = [theSwitch, theBait], theBait = _ref[0], theSwitch = _ref[1];;alert(theBa But it's also helpful for dealing with functions that return multiple values. -weatherReport = (location) ->= (location) -> +weatherReport = (location) -> # Make an Ajax request to fetch the weather... [location, 72, "Mostly Sunny"] @@ -1477,7 +1477,7 @@ futurists = { } }; _ref = futurists.poet, name = _ref.name, _ref2 = _ref.address, street = _ref2[0], city = _ref2[1]; -