jashkenas--coffeescript/documentation/js/overview.js

44 lines
934 B
JavaScript
Raw Normal View History

(function(){
2010-02-21 16:45:03 +00:00
var _a, _b, _c, cubed_list, list, math, num, number, opposite_day, race, square;
// Assignment:
2009-12-26 07:17:34 +00:00
number = 42;
opposite_day = true;
// Conditions:
if (opposite_day) {
number = -42;
}
// Functions:
square = function square(x) {
return x * x;
};
// Arrays:
2009-12-26 07:17:34 +00:00
list = [1, 2, 3, 4, 5];
// Objects:
2009-12-26 07:17:34 +00:00
math = {
root: Math.sqrt,
square: square,
cube: function cube(x) {
return x * square(x);
}
};
2010-01-05 05:34:18 +00:00
// Splats:
race = function race(winner) {
var runners;
runners = Array.prototype.slice.call(arguments, 1);
return print(winner, runners);
};
// Existence:
if ((typeof elvis !== "undefined" && elvis !== null)) {
alert("I knew it!");
}
// Array comprehensions:
cubed_list = (function() {
2010-02-21 16:45:03 +00:00
_a = []; _b = list;
for (_c = 0; _c < _b.length; _c++) {
num = _b[_c];
_a.push(math.cube(num));
}
2010-02-21 16:45:03 +00:00
return _a;
2010-01-25 05:14:00 +00:00
}).call(this);
2010-02-24 23:27:10 +00:00
})();