mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
redoc
This commit is contained in:
parent
585298dc17
commit
c37f284771
49 changed files with 621 additions and 16 deletions
24
documentation/coffee/aliases.js
Normal file
24
documentation/coffee/aliases.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var volume, winner;
|
||||
|
||||
if (ignition === true) {
|
||||
launch();
|
||||
}
|
||||
|
||||
if (band !== SpinalTap) {
|
||||
volume = 10;
|
||||
}
|
||||
|
||||
if (answer !== false) {
|
||||
letTheWildRumpusBegin();
|
||||
}
|
||||
|
||||
if (car.speed < limit) {
|
||||
accelerate();
|
||||
}
|
||||
|
||||
if (pick === 47 || pick === 92 || pick === 13) {
|
||||
winner = true;
|
||||
}
|
||||
|
||||
print(inspect("My name is " + this.name));
|
24
documentation/coffee/array_comprehensions.js
Normal file
24
documentation/coffee/array_comprehensions.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var courses, dish, food, foods, i, j, k, l, len, len1, len2, ref;
|
||||
|
||||
ref = ['toast', 'cheese', 'wine'];
|
||||
for (j = 0, len = ref.length; j < len; j++) {
|
||||
food = ref[j];
|
||||
eat(food);
|
||||
}
|
||||
|
||||
courses = ['greens', 'caviar', 'truffles', 'roast', 'cake'];
|
||||
|
||||
for (i = k = 0, len1 = courses.length; k < len1; i = ++k) {
|
||||
dish = courses[i];
|
||||
menu(i + 1, dish);
|
||||
}
|
||||
|
||||
foods = ['broccoli', 'spinach', 'chocolate'];
|
||||
|
||||
for (l = 0, len2 = foods.length; l < len2; l++) {
|
||||
food = foods[l];
|
||||
if (food !== 'chocolate') {
|
||||
eat(food);
|
||||
}
|
||||
}
|
7
documentation/coffee/block_comment.js
Normal file
7
documentation/coffee/block_comment.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
|
||||
/*
|
||||
SkinnyMochaHalfCaffScript Compiler v1.0
|
||||
Released under the MIT License
|
||||
*/
|
||||
|
14
documentation/coffee/cake_tasks.js
Normal file
14
documentation/coffee/cake_tasks.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var fs;
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
option('-o', '--output [DIR]', 'directory for compiled code');
|
||||
|
||||
task('build:parser', 'rebuild the Jison parser', function(options) {
|
||||
var code, dir;
|
||||
require('jison');
|
||||
code = require('./lib/grammar').parser.generate();
|
||||
dir = options.output || 'lib';
|
||||
return fs.writeFile(dir + "/parser.js", code);
|
||||
});
|
4
documentation/coffee/chaining.js
Normal file
4
documentation/coffee/chaining.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
$('body').click(function(e) {
|
||||
return $('.box').fadeIn('fast').addClass('.active');
|
||||
}).css('background', 'white');
|
57
documentation/coffee/classes.js
Normal file
57
documentation/coffee/classes.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var Animal, Horse, Snake, sam, tom,
|
||||
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
||||
hasProp = {}.hasOwnProperty;
|
||||
|
||||
Animal = (function() {
|
||||
function Animal(name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
Animal.prototype.move = function(meters) {
|
||||
return alert(this.name + (" moved " + meters + "m."));
|
||||
};
|
||||
|
||||
return Animal;
|
||||
|
||||
})();
|
||||
|
||||
Snake = (function(superClass) {
|
||||
extend(Snake, superClass);
|
||||
|
||||
function Snake() {
|
||||
return Snake.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
Snake.prototype.move = function() {
|
||||
alert("Slithering...");
|
||||
return Snake.__super__.move.call(this, 5);
|
||||
};
|
||||
|
||||
return Snake;
|
||||
|
||||
})(Animal);
|
||||
|
||||
Horse = (function(superClass) {
|
||||
extend(Horse, superClass);
|
||||
|
||||
function Horse() {
|
||||
return Horse.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
Horse.prototype.move = function() {
|
||||
alert("Galloping...");
|
||||
return Horse.__super__.move.call(this, 45);
|
||||
};
|
||||
|
||||
return Horse;
|
||||
|
||||
})(Animal);
|
||||
|
||||
sam = new Snake("Sammy the Python");
|
||||
|
||||
tom = new Horse("Tommy the Palomino");
|
||||
|
||||
sam.move();
|
||||
|
||||
tom.move();
|
6
documentation/coffee/comparisons.js
Normal file
6
documentation/coffee/comparisons.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var cholesterol, healthy;
|
||||
|
||||
cholesterol = 127;
|
||||
|
||||
healthy = (200 > cholesterol && cholesterol > 60);
|
15
documentation/coffee/conditionals.js
Normal file
15
documentation/coffee/conditionals.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var date, mood;
|
||||
|
||||
if (singing) {
|
||||
mood = greatlyImproved;
|
||||
}
|
||||
|
||||
if (happy && knowsIt) {
|
||||
clapsHands();
|
||||
chaChaCha();
|
||||
} else {
|
||||
showIt();
|
||||
}
|
||||
|
||||
date = friday ? sue : jill;
|
15
documentation/coffee/constructor_destructuring.js
Normal file
15
documentation/coffee/constructor_destructuring.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var Person, tim;
|
||||
|
||||
Person = (function() {
|
||||
function Person(options) {
|
||||
this.name = options.name, this.age = options.age, this.height = options.height;
|
||||
}
|
||||
|
||||
return Person;
|
||||
|
||||
})();
|
||||
|
||||
tim = new Person({
|
||||
age: 4
|
||||
});
|
9
documentation/coffee/default_args.js
Normal file
9
documentation/coffee/default_args.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var fill;
|
||||
|
||||
fill = function(container, liquid) {
|
||||
if (liquid == null) {
|
||||
liquid = "coffee";
|
||||
}
|
||||
return "Filling the " + container + " with " + liquid + "...";
|
||||
};
|
12
documentation/coffee/do.js
Normal file
12
documentation/coffee/do.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var filename, fn, i, len;
|
||||
|
||||
fn = function(filename) {
|
||||
return fs.readFile(filename, function(err, contents) {
|
||||
return compile(filename, contents.toString());
|
||||
});
|
||||
};
|
||||
for (i = 0, len = list.length; i < len; i++) {
|
||||
filename = list[i];
|
||||
fn(filename);
|
||||
}
|
6
documentation/coffee/embedded.js
Normal file
6
documentation/coffee/embedded.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var hi;
|
||||
|
||||
hi = function() {
|
||||
return [document.title, "Hello JavaScript"].join(": ");
|
||||
};
|
14
documentation/coffee/existence.js
Normal file
14
documentation/coffee/existence.js
Normal file
|
@ -0,0 +1,14 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var footprints, solipsism, speed;
|
||||
|
||||
if ((typeof mind !== "undefined" && mind !== null) && (typeof world === "undefined" || world === null)) {
|
||||
solipsism = true;
|
||||
}
|
||||
|
||||
speed = 0;
|
||||
|
||||
if (speed == null) {
|
||||
speed = 15;
|
||||
}
|
||||
|
||||
footprints = typeof yeti !== "undefined" && yeti !== null ? yeti : "bear";
|
6
documentation/coffee/expansion.js
Normal file
6
documentation/coffee/expansion.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var first, last, ref, text;
|
||||
|
||||
text = "Every literary critic believes he will outwit history and have the last word";
|
||||
|
||||
ref = text.split(" "), first = ref[0], last = ref[ref.length - 1];
|
18
documentation/coffee/expressions.js
Normal file
18
documentation/coffee/expressions.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var eldest, grade;
|
||||
|
||||
grade = function(student) {
|
||||
if (student.excellentWork) {
|
||||
return "A+";
|
||||
} else if (student.okayStuff) {
|
||||
if (student.triedHard) {
|
||||
return "B";
|
||||
} else {
|
||||
return "B-";
|
||||
}
|
||||
} else {
|
||||
return "C";
|
||||
}
|
||||
};
|
||||
|
||||
eldest = 24 > 21 ? "Liz" : "Ike";
|
4
documentation/coffee/expressions_assignment.js
Normal file
4
documentation/coffee/expressions_assignment.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var one, six, three, two;
|
||||
|
||||
six = (one = 1) + (two = 2) + (three = 3);
|
11
documentation/coffee/expressions_comprehension.js
Normal file
11
documentation/coffee/expressions_comprehension.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var globals, name;
|
||||
|
||||
globals = ((function() {
|
||||
var results;
|
||||
results = [];
|
||||
for (name in window) {
|
||||
results.push(name);
|
||||
}
|
||||
return results;
|
||||
})()).slice(0, 10);
|
11
documentation/coffee/expressions_try.js
Normal file
11
documentation/coffee/expressions_try.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var error;
|
||||
|
||||
alert((function() {
|
||||
try {
|
||||
return nonexistent / void 0;
|
||||
} catch (_error) {
|
||||
error = _error;
|
||||
return "And the error is ... " + error;
|
||||
}
|
||||
})());
|
12
documentation/coffee/fat_arrow.js
Normal file
12
documentation/coffee/fat_arrow.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var Account;
|
||||
|
||||
Account = function(customer, cart) {
|
||||
this.customer = customer;
|
||||
this.cart = cart;
|
||||
return $('.shopping_cart').on('click', (function(_this) {
|
||||
return function(event) {
|
||||
return _this.customer.purchase(_this.cart);
|
||||
};
|
||||
})(this));
|
||||
};
|
10
documentation/coffee/functions.js
Normal file
10
documentation/coffee/functions.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var cube, square;
|
||||
|
||||
square = function(x) {
|
||||
return x * x;
|
||||
};
|
||||
|
||||
cube = function(x) {
|
||||
return square(x) * x;
|
||||
};
|
13
documentation/coffee/generators.js
Normal file
13
documentation/coffee/generators.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var perfectSquares;
|
||||
|
||||
perfectSquares = function*() {
|
||||
var num;
|
||||
num = 0;
|
||||
while (true) {
|
||||
num += 1;
|
||||
(yield num * num);
|
||||
}
|
||||
};
|
||||
|
||||
window.ps || (window.ps = perfectSquares());
|
4
documentation/coffee/heredocs.js
Normal file
4
documentation/coffee/heredocs.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var html;
|
||||
|
||||
html = "<strong>\n cup of coffeescript\n</strong>";
|
4
documentation/coffee/heregexes.js
Normal file
4
documentation/coffee/heregexes.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var OPERATOR;
|
||||
|
||||
OPERATOR = /^(?:[-=]>|[-+*\/%<>&|^!?=]=|>>>=?|([-+:])\1|([&|<>])\2=?|\?\.|\.{2,3})/;
|
|
@ -3,5 +3,6 @@ quote = "A picture is a fact. -- #{ author }"
|
|||
|
||||
sentence = "#{ 22 / 7 } is a decent approximation of π"
|
||||
|
||||
direction = "top"
|
||||
window.scrollBy "#{direction}": 100
|
||||
|
||||
|
||||
|
||||
|
|
8
documentation/coffee/interpolation.js
Normal file
8
documentation/coffee/interpolation.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var author, quote, sentence;
|
||||
|
||||
author = "Wittgenstein";
|
||||
|
||||
quote = "A picture is a fact. -- " + author;
|
||||
|
||||
sentence = (22 / 7) + " is a decent approximation of π";
|
8
documentation/coffee/modulo.js
Normal file
8
documentation/coffee/modulo.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var modulo = function(a, b) { return (+a % (b = +b) + b) % b; };
|
||||
|
||||
-7 % 5 === -2;
|
||||
|
||||
modulo(-7, 5) === 3;
|
||||
|
||||
tabs.selectTabAtIndex(modulo(tabs.currentIndex - count, tabs.length));
|
8
documentation/coffee/multiple_return_values.js
Normal file
8
documentation/coffee/multiple_return_values.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var city, forecast, ref, temp, weatherReport;
|
||||
|
||||
weatherReport = function(location) {
|
||||
return [location, 72, "Mostly Sunny"];
|
||||
};
|
||||
|
||||
ref = weatherReport("Berkeley, CA"), city = ref[0], temp = ref[1], forecast = ref[2];
|
18
documentation/coffee/object_comprehensions.js
Normal file
18
documentation/coffee/object_comprehensions.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var age, ages, child, yearsOld;
|
||||
|
||||
yearsOld = {
|
||||
max: 10,
|
||||
ida: 9,
|
||||
tim: 11
|
||||
};
|
||||
|
||||
ages = (function() {
|
||||
var results;
|
||||
results = [];
|
||||
for (child in yearsOld) {
|
||||
age = yearsOld[child];
|
||||
results.push(child + " is " + age);
|
||||
}
|
||||
return results;
|
||||
})();
|
13
documentation/coffee/object_extraction.js
Normal file
13
documentation/coffee/object_extraction.js
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var city, futurists, name, ref, ref1, street;
|
||||
|
||||
futurists = {
|
||||
sculptor: "Umberto Boccioni",
|
||||
painter: "Vladimir Burliuk",
|
||||
poet: {
|
||||
name: "F.T. Marinetti",
|
||||
address: ["Via Roma 42R", "Bellagio, Italy 22021"]
|
||||
}
|
||||
};
|
||||
|
||||
ref = futurists.poet, name = ref.name, (ref1 = ref.address, street = ref1[0], city = ref1[1]);
|
22
documentation/coffee/objects_and_arrays.js
Normal file
22
documentation/coffee/objects_and_arrays.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var bitlist, kids, singers, song;
|
||||
|
||||
song = ["do", "re", "mi", "fa", "so"];
|
||||
|
||||
singers = {
|
||||
Jagger: "Rock",
|
||||
Elvis: "Roll"
|
||||
};
|
||||
|
||||
bitlist = [1, 0, 1, 0, 0, 1, 1, 1, 0];
|
||||
|
||||
kids = {
|
||||
brother: {
|
||||
name: "Max",
|
||||
age: 11
|
||||
},
|
||||
sister: {
|
||||
name: "Ida",
|
||||
age: 9
|
||||
}
|
||||
};
|
6
documentation/coffee/objects_reserved.js
Normal file
6
documentation/coffee/objects_reserved.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
$('.account').attr({
|
||||
"class": 'active'
|
||||
});
|
||||
|
||||
log(object["class"]);
|
45
documentation/coffee/overview.js
Normal file
45
documentation/coffee/overview.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var cubes, list, math, num, number, opposite, race, square,
|
||||
slice = [].slice;
|
||||
|
||||
number = 42;
|
||||
|
||||
opposite = true;
|
||||
|
||||
if (opposite) {
|
||||
number = -42;
|
||||
}
|
||||
|
||||
square = function(x) {
|
||||
return x * x;
|
||||
};
|
||||
|
||||
list = [1, 2, 3, 4, 5];
|
||||
|
||||
math = {
|
||||
root: Math.sqrt,
|
||||
square: square,
|
||||
cube: function(x) {
|
||||
return x * square(x);
|
||||
}
|
||||
};
|
||||
|
||||
race = function() {
|
||||
var runners, winner;
|
||||
winner = arguments[0], runners = 2 <= arguments.length ? slice.call(arguments, 1) : [];
|
||||
return print(winner, runners);
|
||||
};
|
||||
|
||||
if (typeof elvis !== "undefined" && elvis !== null) {
|
||||
alert("I knew it!");
|
||||
}
|
||||
|
||||
cubes = (function() {
|
||||
var i, len, results;
|
||||
results = [];
|
||||
for (i = 0, len = list.length; i < len; i++) {
|
||||
num = list[i];
|
||||
results.push(math.cube(num));
|
||||
}
|
||||
return results;
|
||||
})();
|
8
documentation/coffee/parallel_assignment.js
Normal file
8
documentation/coffee/parallel_assignment.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var ref, theBait, theSwitch;
|
||||
|
||||
theBait = 1000;
|
||||
|
||||
theSwitch = 0;
|
||||
|
||||
ref = [theSwitch, theBait], theBait = ref[0], theSwitch = ref[1];
|
7
documentation/coffee/patterns_and_splats.js
Normal file
7
documentation/coffee/patterns_and_splats.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var close, contents, i, open, ref, tag,
|
||||
slice = [].slice;
|
||||
|
||||
tag = "<impossible>";
|
||||
|
||||
ref = tag.split(""), open = ref[0], contents = 3 <= ref.length ? slice.call(ref, 1, i = ref.length - 1) : (i = 1, []), close = ref[i++];
|
4
documentation/coffee/prototypes.js
vendored
Normal file
4
documentation/coffee/prototypes.js
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
String.prototype.dasherize = function() {
|
||||
return this.replace(/_/g, "-");
|
||||
};
|
11
documentation/coffee/range_comprehensions.js
Normal file
11
documentation/coffee/range_comprehensions.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var countdown, num;
|
||||
|
||||
countdown = (function() {
|
||||
var i, results;
|
||||
results = [];
|
||||
for (num = i = 10; i >= 1; num = --i) {
|
||||
results.push(num);
|
||||
}
|
||||
return results;
|
||||
})();
|
12
documentation/coffee/scope.js
Normal file
12
documentation/coffee/scope.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var changeNumbers, inner, outer;
|
||||
|
||||
outer = 1;
|
||||
|
||||
changeNumbers = function() {
|
||||
var inner;
|
||||
inner = -1;
|
||||
return outer = 10;
|
||||
};
|
||||
|
||||
inner = changeNumbers();
|
12
documentation/coffee/slices.js
Normal file
12
documentation/coffee/slices.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var copy, end, middle, numbers, start;
|
||||
|
||||
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
||||
start = numbers.slice(0, 3);
|
||||
|
||||
middle = numbers.slice(3, -2);
|
||||
|
||||
end = numbers.slice(-2);
|
||||
|
||||
copy = numbers.slice(0);
|
4
documentation/coffee/soaks.js
Normal file
4
documentation/coffee/soaks.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var ref, zip;
|
||||
|
||||
zip = typeof lottery.drawWinner === "function" ? (ref = lottery.drawWinner().address) != null ? ref.zipcode : void 0 : void 0;
|
23
documentation/coffee/splats.js
Normal file
23
documentation/coffee/splats.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var awardMedals, contenders, gold, rest, silver,
|
||||
slice = [].slice;
|
||||
|
||||
gold = silver = rest = "unknown";
|
||||
|
||||
awardMedals = function() {
|
||||
var first, others, second;
|
||||
first = arguments[0], second = arguments[1], others = 3 <= arguments.length ? slice.call(arguments, 2) : [];
|
||||
gold = first;
|
||||
silver = second;
|
||||
return rest = others;
|
||||
};
|
||||
|
||||
contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"];
|
||||
|
||||
awardMedals.apply(null, contenders);
|
||||
|
||||
alert("Gold: " + gold);
|
||||
|
||||
alert("Silver: " + silver);
|
||||
|
||||
alert("The Field: " + rest);
|
6
documentation/coffee/splices.js
Normal file
6
documentation/coffee/splices.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var numbers, ref;
|
||||
|
||||
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
|
||||
[].splice.apply(numbers, [3, 4].concat(ref = [-3, -4, -5, -6])), ref;
|
|
@ -4,3 +4,5 @@ mobyDick = "Call me Ishmael. Some years ago --
|
|||
to interest me on shore, I thought I would sail
|
||||
about a little and see the watery part of the
|
||||
world..."
|
||||
|
||||
|
||||
|
|
4
documentation/coffee/strings.js
Normal file
4
documentation/coffee/strings.js
Normal file
|
@ -0,0 +1,4 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var mobyDick;
|
||||
|
||||
mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world...";
|
24
documentation/coffee/switch.js
Normal file
24
documentation/coffee/switch.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
switch (day) {
|
||||
case "Mon":
|
||||
go(work);
|
||||
break;
|
||||
case "Tue":
|
||||
go(relax);
|
||||
break;
|
||||
case "Thu":
|
||||
go(iceFishing);
|
||||
break;
|
||||
case "Fri":
|
||||
case "Sat":
|
||||
if (day === bingoDay) {
|
||||
go(bingo);
|
||||
go(dancing);
|
||||
}
|
||||
break;
|
||||
case "Sun":
|
||||
go(church);
|
||||
break;
|
||||
default:
|
||||
go(work);
|
||||
}
|
19
documentation/coffee/switch_with_no_expression.js
Normal file
19
documentation/coffee/switch_with_no_expression.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var grade, score;
|
||||
|
||||
score = 76;
|
||||
|
||||
grade = (function() {
|
||||
switch (false) {
|
||||
case !(score < 60):
|
||||
return 'F';
|
||||
case !(score < 70):
|
||||
return 'D';
|
||||
case !(score < 80):
|
||||
return 'C';
|
||||
case !(score < 90):
|
||||
return 'B';
|
||||
default:
|
||||
return 'A';
|
||||
}
|
||||
})();
|
12
documentation/coffee/try.js
Normal file
12
documentation/coffee/try.js
Normal file
|
@ -0,0 +1,12 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var error;
|
||||
|
||||
try {
|
||||
allHellBreaksLoose();
|
||||
catsAndDogsLivingTogether();
|
||||
} catch (_error) {
|
||||
error = _error;
|
||||
print(error);
|
||||
} finally {
|
||||
cleanUp();
|
||||
}
|
22
documentation/coffee/while.js
Normal file
22
documentation/coffee/while.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var lyrics, num;
|
||||
|
||||
if (this.studyingEconomics) {
|
||||
while (supply > demand) {
|
||||
buy();
|
||||
}
|
||||
while (!(supply > demand)) {
|
||||
sell();
|
||||
}
|
||||
}
|
||||
|
||||
num = 6;
|
||||
|
||||
lyrics = (function() {
|
||||
var results;
|
||||
results = [];
|
||||
while (num -= 1) {
|
||||
results.push(num + " little monkeys, jumping on the bed. One fell out and bumped his head.");
|
||||
}
|
||||
return results;
|
||||
})();
|
|
@ -1,16 +1,8 @@
|
|||
// Generated by CoffeeScript 1.9.3
|
||||
var author, direction, obj, quote, sentence;
|
||||
var author, quote, sentence;
|
||||
|
||||
author = "Wittgenstein";
|
||||
|
||||
quote = "A picture is a fact. -- " + author;
|
||||
|
||||
sentence = (22 / 7) + " is a decent approximation of π";
|
||||
|
||||
direction = "top";
|
||||
|
||||
window.scrollBy((
|
||||
obj = {},
|
||||
obj["" + direction] = 100,
|
||||
obj
|
||||
));
|
||||
|
|
24
index.html
24
index.html
|
@ -1329,7 +1329,18 @@ alert((function() {
|
|||
JavaScript, while <tt>%%</tt> provides
|
||||
<a href="http://en.wikipedia.org/wiki/Modulo_operation">“dividend dependent modulo”</a>:
|
||||
</p>
|
||||
|
||||
<div class='code'><pre><code>-<span class="number">7</span> % <span class="number">5</span> == -<span class="number">2</span> <span class="comment"># The remainder of 7 / 5</span>
|
||||
-<span class="number">7</span> %% <span class="number">5</span> == <span class="number">3</span> <span class="comment"># n %% 5 is always between 0 and 4</span>
|
||||
|
||||
tabs.selectTabAtIndex((tabs.currentIndex - count) %% tabs.length)
|
||||
</code></pre><pre><code><span class="keyword">var</span> modulo = <span class="function"><span class="keyword">function</span><span class="params">(a, b)</span> {</span> <span class="keyword">return</span> (+a % (b = +b) + b) % b; };
|
||||
|
||||
-<span class="number">7</span> % <span class="number">5</span> === -<span class="number">2</span>;
|
||||
|
||||
modulo(-<span class="number">7</span>, <span class="number">5</span>) === <span class="number">3</span>;
|
||||
|
||||
tabs.selectTabAtIndex(modulo(tabs.currentIndex - count, tabs.length));
|
||||
</code></pre><script>window.example20 = "-7 % 5 == -2 # The remainder of 7 / 5\n-7 %% 5 == 3 # n %% 5 is always between 0 and 4\n\ntabs.selectTabAtIndex((tabs.currentIndex - count) %% tabs.length)\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example20);'>load</div><br class='clear' /></div>
|
||||
<p>
|
||||
All together now:
|
||||
</p>
|
||||
|
@ -2097,8 +2108,9 @@ quote = <span class="string">"A picture is a fact. -- <span class="subst">#{ au
|
|||
|
||||
sentence = <span class="string">"<span class="subst">#{ <span class="number">22</span> / <span class="number">7</span> }</span> is a decent approximation of π"</span>
|
||||
|
||||
direction = <span class="string">"top"</span>
|
||||
<span class="built_in">window</span>.scrollBy <span class="string">"<span class="subst">#{direction}</span>"</span>: <span class="number">100</span>
|
||||
|
||||
|
||||
|
||||
</code></pre><pre><code><span class="keyword">var</span> author, quote, sentence;
|
||||
|
||||
author = <span class="string">"Wittgenstein"</span>;
|
||||
|
@ -2106,7 +2118,7 @@ author = <span class="string">"Wittgenstein"</span>;
|
|||
quote = <span class="string">"A picture is a fact. -- "</span> + author;
|
||||
|
||||
sentence = (<span class="number">22</span> / <span class="number">7</span>) + <span class="string">" is a decent approximation of π"</span>;
|
||||
</code></pre><script>window.example39 = "author = \"Wittgenstein\"\nquote = \"A picture is a fact. -- #{ author }\"\n\nsentence = \"#{ 22 / 7 } is a decent approximation of π\"\n\ndirection = \"top\"\nwindow.scrollBy \"#{direction}\": 100\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example39);'>load</div><div class='minibutton ok' onclick='javascript: var author, quote, sentence;
|
||||
</code></pre><script>window.example39 = "author = \"Wittgenstein\"\nquote = \"A picture is a fact. -- #{ author }\"\n\nsentence = \"#{ 22 / 7 } is a decent approximation of π\"\n\n\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example39);'>load</div><div class='minibutton ok' onclick='javascript: var author, quote, sentence;
|
||||
|
||||
author = "Wittgenstein";
|
||||
|
||||
|
@ -2123,10 +2135,12 @@ sentence = (22 / 7) + " is a decent approximation of π";
|
|||
to interest me on shore, I thought I would sail
|
||||
about a little and see the watery part of the
|
||||
world..."</span>
|
||||
|
||||
|
||||
</code></pre><pre><code><span class="keyword">var</span> mobyDick;
|
||||
|
||||
mobyDick = <span class="string">"Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world..."</span>;
|
||||
</code></pre><script>window.example40 = "mobyDick = \"Call me Ishmael. Some years ago --\n never mind how long precisely -- having little\n or no money in my purse, and nothing particular\n to interest me on shore, I thought I would sail\n about a little and see the watery part of the\n world...\"\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example40);'>load</div><div class='minibutton ok' onclick='javascript: var mobyDick;
|
||||
</code></pre><script>window.example40 = "mobyDick = \"Call me Ishmael. Some years ago --\n never mind how long precisely -- having little\n or no money in my purse, and nothing particular\n to interest me on shore, I thought I would sail\n about a little and see the watery part of the\n world...\"\n\n\n"</script><div class='minibutton load' onclick='javascript: loadConsole(example40);'>load</div><div class='minibutton ok' onclick='javascript: var mobyDick;
|
||||
|
||||
mobyDick = "Call me Ishmael. Some years ago -- never mind how long precisely -- having little or no money in my purse, and nothing particular to interest me on shore, I thought I would sail about a little and see the watery part of the world...";
|
||||
;alert(mobyDick);'>run: mobyDick</div><br class='clear' /></div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue