2013-08-14 15:12:27 +04:00
|
|
|
---
|
|
|
|
language: coffeescript
|
|
|
|
lang: es-es
|
|
|
|
contributors:
|
|
|
|
- ["Tenor Biel", "http://github.com/L8D"]
|
|
|
|
translators:
|
|
|
|
- ["Pablo Elices", "http://github.com/pabloelices"]
|
|
|
|
filename: coffeescript-es.coffee
|
|
|
|
---
|
|
|
|
|
|
|
|
``` coffeescript
|
|
|
|
# CoffeeScript es un lenguaje hipster.
|
|
|
|
# Tiene convenciones de muchos lenguajes modernos.
|
2013-08-14 15:13:56 +04:00
|
|
|
# Los comentarios son como en Ruby y Python, usan almohadillas.
|
2013-08-14 15:12:27 +04:00
|
|
|
|
|
|
|
###
|
2013-08-14 19:56:15 +04:00
|
|
|
Los comentarios en bloque son como estos, y se traducen directamente a '/*' y '*/'
|
|
|
|
para el código JavaScript resultante.
|
2013-08-14 15:12:27 +04:00
|
|
|
|
|
|
|
Deberías entender la mayor parte de la semántica de JavaScript antes de continuar.
|
|
|
|
###
|
|
|
|
|
|
|
|
# Asignación:
|
|
|
|
number = 42 #=> var number = 42;
|
|
|
|
opposite = true #=> var opposite = true;
|
|
|
|
|
|
|
|
# Condiciones:
|
|
|
|
number = -42 if opposite #=> if(opposite) { number = -42; }
|
|
|
|
|
|
|
|
# Funciones:
|
|
|
|
square = (x) -> x * x #=> var square = function(x) { return x * x; }
|
|
|
|
|
|
|
|
# Rangos:
|
|
|
|
list = [1..5] #=> var list = [1, 2, 3, 4, 5];
|
|
|
|
|
|
|
|
# Objetos:
|
|
|
|
math =
|
|
|
|
root: Math.sqrt
|
|
|
|
square: square
|
|
|
|
cube: (x) -> x * square x
|
|
|
|
#=> var math = {
|
|
|
|
# "root": Math.sqrt,
|
|
|
|
# "square": square,
|
|
|
|
# "cube": function(x) { return x * square(x); }
|
|
|
|
#}
|
|
|
|
|
2013-10-12 19:56:51 +04:00
|
|
|
# Número de argumentos variable:
|
2013-08-14 15:12:27 +04:00
|
|
|
race = (winner, runners...) ->
|
|
|
|
print winner, runners
|
|
|
|
|
|
|
|
# Existencia:
|
|
|
|
alert "I knew it!" if elvis?
|
|
|
|
#=> if(typeof elvis !== "undefined" && elvis !== null) { alert("I knew it!"); }
|
|
|
|
|
2013-10-12 19:56:51 +04:00
|
|
|
# Listas:
|
2013-08-14 15:12:27 +04:00
|
|
|
cubes = (math.cube num for num in list) #=> ...
|
|
|
|
```
|