mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-13 16:57:54 -05:00
Compare commits
719 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
44398d044f | ||
|
|
3feb874b1e | ||
|
|
f7183e6918 | ||
|
|
707cd2d734 | ||
|
|
c11c3ed2f2 | ||
|
|
5fd0972b5d | ||
|
|
70cb195e6f | ||
|
|
c219adffd5 | ||
|
|
cd6dd5abfd | ||
|
|
29ece0e6ba | ||
|
|
45bad556ab | ||
|
|
30cf63ec92 | ||
|
|
969c2e528d | ||
|
|
bb2bf7ce57 | ||
|
|
2969e156c7 | ||
|
|
b08995cbcc | ||
|
|
47f71f9193 | ||
|
|
fec2eaef7e | ||
|
|
56eb474bf3 | ||
|
|
62b2ab29cd | ||
|
|
a35693554c | ||
|
|
f7427259ee | ||
|
|
e02ab76edf | ||
|
|
9f46c306e5 | ||
|
|
b5c9d779bd | ||
|
|
d2cb1f321e | ||
|
|
8f871a8218 | ||
|
|
4ec7514d10 | ||
|
|
1c7e4c4203 | ||
|
|
7d39fe1c56 | ||
|
|
afa26c37f1 | ||
|
|
2f658ba925 | ||
|
|
0ab810e4cb | ||
|
|
37d086b670 | ||
|
|
5e7f5f390a | ||
|
|
f4cd0bdf29 | ||
|
|
723ea53585 | ||
|
|
93f644fae2 | ||
|
|
82951a469b | ||
|
|
d2d5f649d3 | ||
|
|
5c7526a741 | ||
|
|
17ea48c543 | ||
|
|
55ed202957 | ||
|
|
d5df5505f9 | ||
|
|
dc7f4b4be0 | ||
|
|
406a18067d | ||
|
|
3ae2ebe5ea | ||
|
|
a23dc6b753 | ||
|
|
5f1d3fd775 | ||
|
|
9d4e06e8a8 | ||
|
|
6bc61ec1a1 | ||
|
|
c62f93f930 | ||
|
|
213ae1430e | ||
|
|
ee5d738827 | ||
|
|
eab9bbf04f | ||
|
|
4ed51536bb | ||
|
|
b32a60585b | ||
|
|
66a6568fe7 | ||
|
|
fe32146adc | ||
|
|
69feac3a01 | ||
|
|
05d95acfc3 | ||
|
|
22674bc536 | ||
|
|
23c5ebb00f | ||
|
|
c14869f008 | ||
|
|
c1427d6558 | ||
|
|
2a46e13d33 | ||
|
|
b26e577244 | ||
|
|
9f8710b631 | ||
|
|
aba8cb1b08 | ||
|
|
92cd80226c | ||
|
|
10d335ccb1 | ||
|
|
4eeb8c4bd2 | ||
|
|
4d146bacb1 | ||
|
|
7de4caffca | ||
|
|
8db0cb9fa5 | ||
|
|
c30b3d3c48 | ||
|
|
52db4fbf8c | ||
|
|
5cd8f2c52c | ||
|
|
5a1aa44393 | ||
|
|
432696d6eb | ||
|
|
3df7bd98f4 | ||
|
|
1f870911c9 | ||
|
|
4bb9392753 | ||
|
|
fdffacfb40 | ||
|
|
a64afe6162 | ||
|
|
15b86a5f7a | ||
|
|
9b78fb67cf | ||
|
|
4817b96bac | ||
|
|
6985802eb3 | ||
|
|
aad0ce162d | ||
|
|
f582b73035 | ||
|
|
e795f41bd2 | ||
|
|
5d541232ef | ||
|
|
07513ba928 | ||
|
|
aded80c101 | ||
|
|
5d893947ea | ||
|
|
535cf28220 | ||
|
|
dbe5328c33 | ||
|
|
6e15a4da0e | ||
|
|
fc51f0ef6c | ||
|
|
1f2c8df5fa | ||
|
|
bea40a7a92 | ||
|
|
f679590bef | ||
|
|
bd61131f5c | ||
|
|
ff25361896 | ||
|
|
08dcc7e107 | ||
|
|
b027b5cf0d | ||
|
|
0f2a2ee11e | ||
|
|
a93229b14d | ||
|
|
2d3f6b80c1 | ||
|
|
9503ea3040 | ||
|
|
08539a156e | ||
|
|
b183b091ee | ||
|
|
c39415da44 | ||
|
|
2c461f6474 | ||
|
|
e213964793 | ||
|
|
dd753d3b78 | ||
|
|
45c0d4c2ea | ||
|
|
4f89f90dab | ||
|
|
0270e48a01 | ||
|
|
a278d8f018 | ||
|
|
d4a180c413 | ||
|
|
28a8c05513 | ||
|
|
879b3d76bd | ||
|
|
138692183b | ||
|
|
95f3e2f79f | ||
|
|
dec9950649 | ||
|
|
2f6b69b580 | ||
|
|
ff1fd97924 | ||
|
|
87e60dccf0 | ||
|
|
8ff977dc65 | ||
|
|
fbfa12c733 | ||
|
|
6a45d25777 | ||
|
|
2b5d596e10 | ||
|
|
e2a71d3c2c | ||
|
|
807e0b479d | ||
|
|
dfa63839bb | ||
|
|
0490cb2920 | ||
|
|
2d0ad73af8 | ||
|
|
5a81fcd42e | ||
|
|
6446e0004c | ||
|
|
edf5f4947e | ||
|
|
b674163a40 | ||
|
|
9f2badb3e9 | ||
|
|
0610e20a3c | ||
|
|
bedc005d67 | ||
|
|
a8a46257ae | ||
|
|
b41afe79b4 | ||
|
|
448ed36cd2 | ||
|
|
c4d19cd1fa | ||
|
|
495ca64c46 | ||
|
|
0f2cf552e9 | ||
|
|
f6a1f16146 | ||
|
|
db6bc0ba02 | ||
|
|
e4bb6c91e7 | ||
|
|
561a02c35f | ||
|
|
51e80484e2 | ||
|
|
79fa4723ab | ||
|
|
a3c8c0b492 | ||
|
|
2f389f1d51 | ||
|
|
85e5dffad5 | ||
|
|
fa63288f52 | ||
|
|
4ea8be8e0b | ||
|
|
48c501a7a2 | ||
|
|
63c2b2bc64 | ||
|
|
639be2ff09 | ||
|
|
8b1b3ea402 | ||
|
|
9c3040b704 | ||
|
|
e7291f57ba | ||
|
|
3f6eceac77 | ||
|
|
ba7a454f92 | ||
|
|
3092d74a08 | ||
|
|
ff8e0c9751 | ||
|
|
3e518e3cf9 | ||
|
|
7667e16732 | ||
|
|
e110042275 | ||
|
|
06677b0545 | ||
|
|
20d105ba4e | ||
|
|
e77f4f61aa | ||
|
|
9de729e825 | ||
|
|
c39c2e3599 | ||
|
|
ecfa212189 | ||
|
|
97fd126a7f | ||
|
|
844c756940 | ||
|
|
a90bf75395 | ||
|
|
79bb0da153 | ||
|
|
c88b1f6a15 | ||
|
|
b224d58a36 | ||
|
|
7d348b5eae | ||
|
|
02ac3edebf | ||
|
|
4bad3e0f4f | ||
|
|
8147ef554a | ||
|
|
785c4fb5a0 | ||
|
|
13b2dc8d31 | ||
|
|
a62923ff97 | ||
|
|
dd6be80fca | ||
|
|
8c077f0f65 | ||
|
|
2c4c4cc93e | ||
|
|
1ab3b183a8 | ||
|
|
e6a53bd852 | ||
|
|
b983b3fcdc | ||
|
|
89cac4071e | ||
|
|
506ea8aa52 | ||
|
|
b965fcf32d | ||
|
|
126f6c2d88 | ||
|
|
3dc456572b | ||
|
|
0f26072ad0 | ||
|
|
dc9cec2611 | ||
|
|
c9aeae757b | ||
|
|
094c2682bd | ||
|
|
066ee52615 | ||
|
|
ee1c9b284a | ||
|
|
d9fba94983 | ||
|
|
e02bedcf82 | ||
|
|
1552470413 | ||
|
|
e2f3c2259b | ||
|
|
249bd99656 | ||
|
|
b36196286a | ||
|
|
b21780b738 | ||
|
|
207ec81821 | ||
|
|
d61aaf393a | ||
|
|
19c44c9b62 | ||
|
|
4deabf5e01 | ||
|
|
1a6194e9f0 | ||
|
|
156a0b13d9 | ||
|
|
61a7f7a567 | ||
|
|
dbcb9df22b | ||
|
|
e2ad1190ac | ||
|
|
c0f9058f15 | ||
|
|
12859e575a | ||
|
|
3f765c356a | ||
|
|
fd8b540a66 | ||
|
|
29267593c2 | ||
|
|
1e74805aa4 | ||
|
|
12685aa54a | ||
|
|
04f07f4c15 | ||
|
|
df386a3b3f | ||
|
|
13c49ad865 | ||
|
|
7c01bba4f4 | ||
|
|
950d1199c2 | ||
|
|
38d1381c02 | ||
|
|
98f15d001f | ||
|
|
a379530d41 | ||
|
|
e19b67cb79 | ||
|
|
e883a559ca | ||
|
|
713f6f32e1 | ||
|
|
872b36c11d | ||
|
|
f761c25dcd | ||
|
|
38e1991f82 | ||
|
|
13d3b3a3ce | ||
|
|
0c2a13b468 | ||
|
|
4e7408dc25 | ||
|
|
76dac9c09c | ||
|
|
9339058fc3 | ||
|
|
8e3e06a6e9 | ||
|
|
fd80d784f4 | ||
|
|
ae4f6309e8 | ||
|
|
c466537a26 | ||
|
|
001c915c21 | ||
|
|
91a7102f11 | ||
|
|
a451e90374 | ||
|
|
c6a6788694 | ||
|
|
522df2a355 | ||
|
|
863de88671 | ||
|
|
cb57a1ca1f | ||
|
|
32098e5a13 | ||
|
|
210d673ef0 | ||
|
|
0b5b6113ee | ||
|
|
d5c98165ea | ||
|
|
b8d22bc572 | ||
|
|
69808ba523 | ||
|
|
aabfba9599 | ||
|
|
135620b14a | ||
|
|
78a4974de9 | ||
|
|
e2d75e6771 | ||
|
|
1aa966bba6 | ||
|
|
a347183f3d | ||
|
|
56499984ca | ||
|
|
7ec0a8d653 | ||
|
|
293c2ffb5b | ||
|
|
5ec096e40d | ||
|
|
47bc1d5fda | ||
|
|
6a59c5c9a9 | ||
|
|
decaea0f5f | ||
|
|
0a1873dc42 | ||
|
|
96eb7e2339 | ||
|
|
b795ae7fe1 | ||
|
|
74b9545dc8 | ||
|
|
0d56b89d12 | ||
|
|
dc7d0f1568 | ||
|
|
9b7cfe87b5 | ||
|
|
1587901367 | ||
|
|
df670d47d2 | ||
|
|
cb7a1033fa | ||
|
|
df588bc9e8 | ||
|
|
9648ae2de1 | ||
|
|
c5c841f2fc | ||
|
|
c8ac7f0533 | ||
|
|
681d4f44f4 | ||
|
|
db00cd6ed4 | ||
|
|
3a748755df | ||
|
|
a0572f161d | ||
|
|
bad50c9aee | ||
|
|
c6457e010d | ||
|
|
557cdbba71 | ||
|
|
84feab3492 | ||
|
|
e755188878 | ||
|
|
babeebcc1a | ||
|
|
f19360c6b9 | ||
|
|
eff2f4b520 | ||
|
|
854c796fd6 | ||
|
|
b0ecb39e9f | ||
|
|
f5a37035cf | ||
|
|
e08e99a403 | ||
|
|
ba2d9df25f | ||
|
|
83285fe170 | ||
|
|
5b2ab36246 | ||
|
|
2f3a94678f | ||
|
|
ca0a65ab95 | ||
|
|
3524d618d8 | ||
|
|
386d3dd307 | ||
|
|
e998a81b63 | ||
|
|
aa93d3c387 | ||
|
|
ab4a4a5580 | ||
|
|
3775f682de | ||
|
|
a9f016e292 | ||
|
|
55df898112 | ||
|
|
fb7fd53bdf | ||
|
|
29e4043f26 | ||
|
|
460b3f6d8e | ||
|
|
63b44a2b03 | ||
|
|
8efcaf6eec | ||
|
|
a732e578ea | ||
|
|
d6e206b420 | ||
|
|
91e703052c | ||
|
|
f393b1c897 | ||
|
|
2875de5e73 | ||
|
|
8d63d269b8 | ||
|
|
a5d39efdd2 | ||
|
|
70e3a6ef2f | ||
|
|
4b267b401a | ||
|
|
e6f010b983 | ||
|
|
af53a04932 | ||
|
|
817e8deb27 | ||
|
|
d728c3d669 | ||
|
|
9160500e84 | ||
|
|
c3ce2ea9b1 | ||
|
|
5f94186b40 | ||
|
|
791d874058 | ||
|
|
a8ae37a428 | ||
|
|
b9c09bfa4e | ||
|
|
63c9b5c2f0 | ||
|
|
80fbe02fda | ||
|
|
e514a39dd2 | ||
|
|
4a32c58221 | ||
|
|
4609ad78c2 | ||
|
|
2d90a751f7 | ||
|
|
8647b54a61 | ||
|
|
8e1f3c0eca | ||
|
|
c4d0903e6a | ||
|
|
e72ef1a61a | ||
|
|
d7d9cb8d28 | ||
|
|
f6c8e81ea6 | ||
|
|
52539ae7d2 | ||
|
|
95b362499f | ||
|
|
0bc4da2b51 | ||
|
|
9679fc0b52 | ||
|
|
9cb0564972 | ||
|
|
c6c0c7d059 | ||
|
|
62e946b8ce | ||
|
|
6c782b7723 | ||
|
|
9eff443032 | ||
|
|
8957feedb4 | ||
|
|
1cd7fa8ebe | ||
|
|
701cdb4c13 | ||
|
|
8dc5da9cc9 | ||
|
|
001cc29deb | ||
|
|
e77e520607 | ||
|
|
ed8a54995d | ||
|
|
2d206e7b60 | ||
|
|
bb9fdd3015 | ||
|
|
1e7d638435 | ||
|
|
0ceca0778c | ||
|
|
abd9ab5c71 | ||
|
|
ea349a1a59 | ||
|
|
f0d5db7e66 | ||
|
|
914ba1c244 | ||
|
|
844ea33274 | ||
|
|
87e04e9952 | ||
|
|
197914bcf7 | ||
|
|
8dfbd1a2a8 | ||
|
|
c19647ad33 | ||
|
|
27f7ef09af | ||
|
|
9a61bbf005 | ||
|
|
c8d505e85d | ||
|
|
477c510345 | ||
|
|
c3029faca7 | ||
|
|
186797a745 | ||
|
|
d54fa2f2a1 | ||
|
|
5e1e949bf6 | ||
|
|
6c980d8adc | ||
|
|
2f63439bff | ||
|
|
c7cb308b6d | ||
|
|
9cc7d6af27 | ||
|
|
cfa357cbc3 | ||
|
|
9d8668f37f | ||
|
|
d1ddeacbe3 | ||
|
|
d9d09a9a72 | ||
|
|
a1528f3f19 | ||
|
|
7d2a955e0a | ||
|
|
24408c785a | ||
|
|
bb5bf7f94f | ||
|
|
3e987de4a8 | ||
|
|
de74bce2cd | ||
|
|
c265b7d5d6 | ||
|
|
ad18378f7e | ||
|
|
902febb43a | ||
|
|
13fc8aea04 | ||
|
|
8ea75290b5 | ||
|
|
9498ef9fe4 | ||
|
|
8e3922b6c6 | ||
|
|
2319affa61 | ||
|
|
7befbddae2 | ||
|
|
ae58e2ec6c | ||
|
|
4c3f00cf77 | ||
|
|
8b3926fb0c | ||
|
|
d416c184db | ||
|
|
30dca132bd | ||
|
|
69908be85c | ||
|
|
c70b6f39b1 | ||
|
|
fab98a2219 | ||
|
|
18c3e79a50 | ||
|
|
9ed8020b84 | ||
|
|
cf7079a379 | ||
|
|
3e33b4a618 | ||
|
|
a5c1922200 | ||
|
|
c49f2d8097 | ||
|
|
eb9b18376e | ||
|
|
fbcdc12a9c | ||
|
|
41bb6edcd2 | ||
|
|
22d3238b2a | ||
|
|
3124869e1d | ||
|
|
de49465dc6 | ||
|
|
4fc40e4841 | ||
|
|
0275e7775f | ||
|
|
001e42b85c | ||
|
|
46f1977ea1 | ||
|
|
c2bb93b5f8 | ||
|
|
1040e52246 | ||
|
|
d555685030 | ||
|
|
5fe419b1ce | ||
|
|
1ebc4d5f21 | ||
|
|
6658250c8e | ||
|
|
724d4c9660 | ||
|
|
0cf7801f36 | ||
|
|
ae603749be | ||
|
|
6e63a18f86 | ||
|
|
3e24cef69f | ||
|
|
2c1033f5da | ||
|
|
da9e38808c | ||
|
|
5efaff506c | ||
|
|
94bc7c1f92 | ||
|
|
f75d98e447 | ||
|
|
69283fcadd | ||
|
|
672dd70bdb | ||
|
|
32cd15f038 | ||
|
|
ecdb47107b | ||
|
|
cb1815885c | ||
|
|
d53d85d03e | ||
|
|
8e6486a1d7 | ||
|
|
97f16c0e9c | ||
|
|
bd2597c6b8 | ||
|
|
56015bd23f | ||
|
|
3724778989 | ||
|
|
bb0dfa5cd4 | ||
|
|
6160fe3c17 | ||
|
|
099944e0aa | ||
|
|
4814d5baa5 | ||
|
|
78c4957ba8 | ||
|
|
de4eddcad4 | ||
|
|
ba3c5298f7 | ||
|
|
21a0cc83ae | ||
|
|
7eff8786bc | ||
|
|
7ee5be674d | ||
|
|
38520bfece | ||
|
|
c3d0e50e8f | ||
|
|
34add7d7bf | ||
|
|
75d9e23df4 | ||
|
|
ff80f8d423 | ||
|
|
3489eec6ee | ||
|
|
2f69bc1708 | ||
|
|
0f81dbe913 | ||
|
|
e30a267c9d | ||
|
|
305f883eab | ||
|
|
f622fc43bc | ||
|
|
a93a570603 | ||
|
|
02fbd28e58 | ||
|
|
2cef93b381 | ||
|
|
caf9d627cb | ||
|
|
ad5b5fa458 | ||
|
|
41056ca2bd | ||
|
|
409283a30f | ||
|
|
abfc9f5a2d | ||
|
|
43edd29d22 | ||
|
|
26c89cef06 | ||
|
|
1d2bb3b2be | ||
|
|
f299972713 | ||
|
|
bfd7455db4 | ||
|
|
7ec91a1ee5 | ||
|
|
44fec922a4 | ||
|
|
07d0044718 | ||
|
|
00538bd62c | ||
|
|
4e8a12d70d | ||
|
|
edf1fc769f | ||
|
|
2231d67cef | ||
|
|
a376e7f4a3 | ||
|
|
20ade4f448 | ||
|
|
f9d630119d | ||
|
|
7f76c22894 | ||
|
|
b1fa06ff70 | ||
|
|
e481a39a0d | ||
|
|
8762162dff | ||
|
|
a6539a030c | ||
|
|
942572d081 | ||
|
|
ec60205014 | ||
|
|
dba8439425 | ||
|
|
774e3d3e31 | ||
|
|
cae0b1a038 | ||
|
|
bbbfd92373 | ||
|
|
fd83759ef4 | ||
|
|
49714656e1 | ||
|
|
d43d491561 | ||
|
|
c8711b419e | ||
|
|
5c7b77aa4d | ||
|
|
dc821f2e4c | ||
|
|
cd68f02981 | ||
|
|
e6cd32f2fc | ||
|
|
ed1c1f7a0e | ||
|
|
5659d1bd49 | ||
|
|
9a7c075e06 | ||
|
|
62c51006a1 | ||
|
|
d528db76e6 | ||
|
|
9a946d2ac5 | ||
|
|
c822f96145 | ||
|
|
9e3ef42c63 | ||
|
|
f93e552cb3 | ||
|
|
ea58be2838 | ||
|
|
4d514f255b | ||
|
|
ce0e71f796 | ||
|
|
7c97f32dd3 | ||
|
|
6ddd808f74 | ||
|
|
90051e9096 | ||
|
|
dd3c9abe15 | ||
|
|
d3ab60df78 | ||
|
|
541291e2f3 | ||
|
|
fd357871f2 | ||
|
|
f5aafc6591 | ||
|
|
96803d0129 | ||
|
|
ae112d6087 | ||
|
|
a3129e05ae | ||
|
|
f44443b58a | ||
|
|
3fbb870d01 | ||
|
|
cea417de02 | ||
|
|
ddd52a1845 | ||
|
|
50bdd2668c | ||
|
|
bb84a982ce | ||
|
|
7b5b261743 | ||
|
|
c84bb0c875 | ||
|
|
a186e47e2c | ||
|
|
41f3d54f4a | ||
|
|
9e47f6bd58 | ||
|
|
3762f4c680 | ||
|
|
845c8cba3b | ||
|
|
a722b42eed | ||
|
|
78e08f316d | ||
|
|
55616cf3b8 | ||
|
|
aa45456d7d | ||
|
|
ac00a19514 | ||
|
|
7ae8687a3e | ||
|
|
55e736cb27 | ||
|
|
3ee4e98ccc | ||
|
|
d7dd18b476 | ||
|
|
097bede5c8 | ||
|
|
983dac84a2 | ||
|
|
eeef8d3612 | ||
|
|
b4250c0f02 | ||
|
|
cc0c92d20d | ||
|
|
694833dbd0 | ||
|
|
fde9852090 | ||
|
|
191875a85b | ||
|
|
556f8cb68a | ||
|
|
5bed5646be | ||
|
|
08dddb27a0 | ||
|
|
2a1fc4b1b7 | ||
|
|
3c67d54bbe | ||
|
|
6a30d48ced | ||
|
|
d59ef71642 | ||
|
|
ff78546465 | ||
|
|
834442148b | ||
|
|
adaae0ccae | ||
|
|
7c132d65dc | ||
|
|
b58102c514 | ||
|
|
52700ca922 | ||
|
|
dd5317ebe9 | ||
|
|
1ba7c77136 | ||
|
|
62485c2b8c | ||
|
|
d46bf8ee71 | ||
|
|
e494d520ea | ||
|
|
f55b4cd8b6 | ||
|
|
763e04fec9 | ||
|
|
4b5db1181c | ||
|
|
bc6ec37272 | ||
|
|
55bf0a2c61 | ||
|
|
968aeec523 | ||
|
|
851ec82495 | ||
|
|
c4ba971d39 | ||
|
|
e7e8e243a2 | ||
|
|
73aaf127c8 | ||
|
|
7a0de52c96 | ||
|
|
2d57ee693b | ||
|
|
d8ceb3b4bb | ||
|
|
beae912a91 | ||
|
|
6865f5be92 | ||
|
|
2f35bba083 | ||
|
|
378e156e11 | ||
|
|
9b2326492b | ||
|
|
93009e07f6 | ||
|
|
985e0a080b | ||
|
|
95bfb0b45c | ||
|
|
65e9ba4c30 | ||
|
|
1c83e68292 | ||
|
|
47812d9ea6 | ||
|
|
a80b532a05 | ||
|
|
42ca566d26 | ||
|
|
e27756cee8 | ||
|
|
46f81c2de1 | ||
|
|
c3ff752c40 | ||
|
|
73a0777705 | ||
|
|
9f80998415 | ||
|
|
dbccc1fa4f | ||
|
|
08248180f9 | ||
|
|
ed504ea6be | ||
|
|
da84906d1e | ||
|
|
aafd3cd6ea | ||
|
|
39ceca477d | ||
|
|
bfb24c6b5d | ||
|
|
7f502543d2 | ||
|
|
5d1ec9d2a9 | ||
|
|
2e8f03b4cc | ||
|
|
840e2b89fc | ||
|
|
c438123a3d | ||
|
|
726a9b229e | ||
|
|
8d76f4bd3f | ||
|
|
849f0e4192 | ||
|
|
47928ca952 | ||
|
|
fb13a303f2 | ||
|
|
b743e3219a | ||
|
|
417753bd62 | ||
|
|
705b293982 | ||
|
|
0a58eeef2b | ||
|
|
b1f3ad24a2 | ||
|
|
2b94849429 | ||
|
|
eae53d4787 | ||
|
|
5f9a190683 | ||
|
|
cdfb5091be | ||
|
|
64879cdc66 | ||
|
|
a4d014549b | ||
|
|
60eabf63cf | ||
|
|
6555473788 | ||
|
|
e916d4648d | ||
|
|
ec58d6fda2 | ||
|
|
65809d08f6 | ||
|
|
d45643c527 | ||
|
|
9b8f018646 | ||
|
|
2f211196a2 | ||
|
|
9bb3e3fbe8 | ||
|
|
c7fa9c320a | ||
|
|
dcc70e5ab0 | ||
|
|
93bdfcb72a | ||
|
|
9ba1ffde21 | ||
|
|
0b2e7f1e59 | ||
|
|
b2e6a34d40 | ||
|
|
ad3b887df4 | ||
|
|
6f81ac3684 | ||
|
|
2f75854a61 | ||
|
|
253e45fc54 | ||
|
|
31639d7d1a | ||
|
|
6ba5d45cbe | ||
|
|
f154ab3d15 | ||
|
|
669c065dd7 | ||
|
|
92adabdddc | ||
|
|
049358d006 | ||
|
|
a50446a0ca | ||
|
|
67bb49ed04 | ||
|
|
1395b05d36 | ||
|
|
83944950ac | ||
|
|
d124f7fc0d | ||
|
|
77704d24a2 | ||
|
|
68bc68c1ac | ||
|
|
8511a33b1e | ||
|
|
6050cad0f8 | ||
|
|
9976de76f5 | ||
|
|
0dc445138b | ||
|
|
3ffbf541df | ||
|
|
e3c667d49d | ||
|
|
2c90e8b002 | ||
|
|
398251ff90 | ||
|
|
9249ceaef5 | ||
|
|
1eec05d23a | ||
|
|
1590713576 | ||
|
|
146b5694c2 | ||
|
|
1d35910567 | ||
|
|
1a8311b9d0 | ||
|
|
4e1e119f58 | ||
|
|
3dac0f6d84 | ||
|
|
962885444e | ||
|
|
d1682f5b3f | ||
|
|
c6f11fbfeb | ||
|
|
290aa257de |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,2 +1,6 @@
|
||||
presentation
|
||||
test.coffee
|
||||
parser.output
|
||||
test/fixtures/underscore
|
||||
examples/beautiful_code/parse.coffee
|
||||
*.gem
|
||||
73
Cakefile
Normal file
73
Cakefile
Normal file
@@ -0,0 +1,73 @@
|
||||
fs: require 'fs'
|
||||
coffee: require 'coffee-script'
|
||||
|
||||
# Run a CoffeeScript through our node/coffee interpreter.
|
||||
run: (args) ->
|
||||
proc: process.createChildProcess 'bin/coffee', args
|
||||
proc.addListener 'error', (err) -> if err then puts err
|
||||
|
||||
|
||||
option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`'
|
||||
|
||||
task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options) ->
|
||||
base: options.prefix or '/usr/local'
|
||||
lib: base + '/lib/coffee-script'
|
||||
exec([
|
||||
'mkdir -p ' + lib
|
||||
'cp -rf bin lib LICENSE README package.json src vendor ' + lib
|
||||
'ln -sf ' + lib + '/bin/coffee ' + base + '/bin/coffee'
|
||||
'ln -sf ' + lib + '/bin/cake ' + base + '/bin/cake'
|
||||
].join(' && '), (err, stdout, stderr) ->
|
||||
if err then print stderr
|
||||
)
|
||||
|
||||
|
||||
task 'build', 'build the CoffeeScript language from source', ->
|
||||
files: fs.readdirSync 'src'
|
||||
files: 'src/' + file for file in files when file.match(/\.coffee$/)
|
||||
run ['-c', '-o', 'lib'].concat(files)
|
||||
|
||||
|
||||
task 'build:parser', 'rebuild the Jison parser (run build first)', ->
|
||||
require.paths.unshift 'vendor/jison/lib'
|
||||
parser: require('grammar').parser
|
||||
js: parser.generate()
|
||||
parser_path: 'lib/parser.js'
|
||||
fs.writeFile parser_path, js
|
||||
|
||||
|
||||
task 'build:ultraviolet', 'build and install the Ultraviolet syntax highlighter', ->
|
||||
exec 'plist2syntax extras/CoffeeScript.tmbundle/Syntaxes/CoffeeScript.tmLanguage', (err) ->
|
||||
exec 'sudo mv coffeescript.yaml /usr/local/lib/ruby/gems/1.8/gems/ultraviolet-0.10.2/syntax/coffeescript.syntax'
|
||||
|
||||
|
||||
task 'build:underscore', 'rebuild the Underscore.coffee documentation page', ->
|
||||
exec 'uv -s coffeescript -t idle -h examples/underscore.coffee > documentation/underscore.html'
|
||||
|
||||
|
||||
task 'build:browser', 'rebuild the merged script for inclusion in the browser', ->
|
||||
exec 'rake browser', (err) ->
|
||||
throw err if err
|
||||
|
||||
|
||||
task 'doc', 'watch and continually rebuild the documentation', ->
|
||||
exec 'rake doc'
|
||||
|
||||
|
||||
task 'test', 'run the CoffeeScript language test suite', ->
|
||||
process.mixin require 'assert'
|
||||
test_count: 0
|
||||
start_time: new Date()
|
||||
[original_ok, original_throws]: [ok, throws]
|
||||
process.mixin {
|
||||
ok: (args...) -> test_count += 1; original_ok(args...)
|
||||
throws: (args...) -> test_count += 1; original_throws(args...)
|
||||
}
|
||||
process.addListener 'exit', ->
|
||||
time: ((new Date() - start_time) / 1000).toFixed(2)
|
||||
puts '\033[0;32mpassed ' + test_count + ' tests in ' + time + ' seconds\033[0m'
|
||||
fs.readdir 'test', (err, files) ->
|
||||
for file in files
|
||||
fs.readFile 'test/' + file, (err, source) ->
|
||||
js: coffee.compile source
|
||||
process.compile js, file
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2009 Jeremy Ashkenas
|
||||
Copyright (c) 2010 Jeremy Ashkenas
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
|
||||
14
README
14
README
@@ -22,17 +22,21 @@
|
||||
|
||||
CoffeeScript is a little language that compiles into JavaScript.
|
||||
|
||||
Install the compiler:
|
||||
gem install coffee-script
|
||||
Install Node.js, and then the CoffeeScript compiler:
|
||||
sudo bin/cake install
|
||||
|
||||
Compile a script:
|
||||
coffee-script /path/to/script.coffee
|
||||
coffee /path/to/script.coffee
|
||||
|
||||
For documentation, usage, and examples, see:
|
||||
http://jashkenas.github.com/coffee-script/
|
||||
http://coffeescript.org/
|
||||
|
||||
To suggest a feature or report a bug:
|
||||
To suggest a feature, report a bug, or general discussion:
|
||||
http://github.com/jashkenas/coffee-script/issues/
|
||||
|
||||
If you'd like to chat, drop by #coffeescript on Freenode IRC,
|
||||
or on webchat.freenode.net.
|
||||
|
||||
The source repository:
|
||||
git://github.com/jashkenas/coffee-script.git
|
||||
|
||||
|
||||
46
Rakefile
46
Rakefile
@@ -1,33 +1,13 @@
|
||||
require 'erb'
|
||||
require 'fileutils'
|
||||
require 'rake/testtask'
|
||||
|
||||
desc "Run all tests"
|
||||
task :test do
|
||||
$LOAD_PATH.unshift(File.expand_path('test'))
|
||||
require 'redgreen' if Gem.available?('redgreen')
|
||||
require 'test/unit'
|
||||
Dir['test/*/**/test_*.rb'].each {|test| require test }
|
||||
end
|
||||
|
||||
namespace :build do
|
||||
|
||||
desc "Recompile the Racc parser (pass -v and -g for verbose debugging)"
|
||||
task :parser, :racc_args do |t, args|
|
||||
sh "racc #{args[:racc_args]} -o lib/coffee_script/parser.rb lib/coffee_script/grammar.y"
|
||||
end
|
||||
|
||||
desc "Compile the Narwhal interface for --interactive and --run"
|
||||
task :narwhal do
|
||||
sh "bin/coffee-script lib/coffee_script/narwhal/*.coffee -o lib/coffee_script/narwhal/js"
|
||||
end
|
||||
|
||||
end
|
||||
require 'rubygems'
|
||||
require 'yui/compressor'
|
||||
|
||||
desc "Build the documentation page"
|
||||
task :doc do
|
||||
source = 'documentation/index.html.erb'
|
||||
child = fork { exec "bin/coffee-script documentation/coffee/*.coffee -o documentation/js -w" }
|
||||
child = fork { exec "bin/coffee -c documentation/coffee/*.coffee -o documentation/js -w" }
|
||||
at_exit { Process.kill("INT", child) }
|
||||
Signal.trap("INT") { exit }
|
||||
loop do
|
||||
@@ -41,19 +21,11 @@ task :doc do
|
||||
end
|
||||
end
|
||||
|
||||
namespace :gem do
|
||||
|
||||
desc 'Build and install the coffee-script gem'
|
||||
task :install do
|
||||
sh "gem build coffee-script.gemspec"
|
||||
sh "sudo gem install #{Dir['*.gem'].join(' ')} --local --no-ri --no-rdoc"
|
||||
end
|
||||
|
||||
desc 'Uninstall the coffee-script gem'
|
||||
task :uninstall do
|
||||
sh "sudo gem uninstall -x coffee-script"
|
||||
end
|
||||
|
||||
desc "Build the single concatenated and minified script for the browser"
|
||||
task :browser do
|
||||
sources = %w(rewriter.js lexer.js parser.js scope.js nodes.js coffee-script.js)
|
||||
code = sources.map {|s| File.read('lib/' + s) }.join('')
|
||||
code = YUI::JavaScriptCompressor.new.compress(code)
|
||||
File.open('extras/coffee-script.js', 'w+') {|f| f.write(code) }
|
||||
end
|
||||
|
||||
task :default => :test
|
||||
9
bin/cake
Executable file
9
bin/cake
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
process.mixin(require('sys'));
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
|
||||
|
||||
require.paths.unshift(lib);
|
||||
require('cake').run();
|
||||
9
bin/coffee
Executable file
9
bin/coffee
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
process.mixin(require('sys'));
|
||||
var path = require('path');
|
||||
var fs = require('fs');
|
||||
var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
|
||||
|
||||
require.paths.unshift(lib);
|
||||
require('command_line').run();
|
||||
@@ -1,5 +0,0 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
require "#{File.dirname(__FILE__)}/../lib/coffee_script/command_line.rb"
|
||||
|
||||
CoffeeScript::CommandLine.new
|
||||
@@ -1,26 +0,0 @@
|
||||
Gem::Specification.new do |s|
|
||||
s.name = 'coffee-script'
|
||||
s.version = '0.1.4' # Keep version in sync with coffee-script.rb
|
||||
s.date = '2009-12-25'
|
||||
|
||||
s.homepage = "http://jashkenas.github.com/coffee-script/"
|
||||
s.summary = "The CoffeeScript Compiler"
|
||||
s.description = <<-EOS
|
||||
CoffeeScript is a little language that compiles into JavaScript. Think
|
||||
of it as JavaScript's less ostentatious kid brother -- the same genes,
|
||||
roughly the same height, but a different sense of style. Apart from a
|
||||
handful of bonus goodies, statements in CoffeeScript correspond
|
||||
one-to-one with their equivalent in JavaScript, it's just another
|
||||
way of saying it.
|
||||
EOS
|
||||
|
||||
s.authors = ['Jeremy Ashkenas']
|
||||
s.email = 'jashkenas@gmail.com'
|
||||
s.rubyforge_project = 'coffee-script'
|
||||
s.has_rdoc = false
|
||||
|
||||
s.require_paths = ['lib']
|
||||
s.executables = ['coffee-script']
|
||||
|
||||
s.files = Dir['bin/*', 'examples/*', 'lib/**/*', 'coffee-script.gemspec', 'LICENSE', 'README']
|
||||
end
|
||||
@@ -4,4 +4,6 @@ volume: 10 if band isnt spinal_tap
|
||||
|
||||
let_the_wild_rumpus_begin() unless answer is no
|
||||
|
||||
if car.speed < speed_limit then accelerate().
|
||||
if car.speed < speed_limit then accelerate()
|
||||
|
||||
print "My name is " + @name
|
||||
|
||||
4
documentation/coffee/arguments.coffee
Normal file
4
documentation/coffee/arguments.coffee
Normal file
@@ -0,0 +1,4 @@
|
||||
backwards: ->
|
||||
alert arguments.reverse()
|
||||
|
||||
backwards "stairway", "to", "heaven"
|
||||
@@ -1,5 +1,7 @@
|
||||
# Eat lunch.
|
||||
lunch: food.eat() for food in ['toast', 'cheese', 'wine'].
|
||||
lunch: eat food for food in ['toast', 'cheese', 'wine']
|
||||
|
||||
# Zebra-stripe a table.
|
||||
highlight(row) for row, i in table if i % 2 is 0.
|
||||
# Naive collision detection.
|
||||
for roid in asteroids
|
||||
for roid2 in asteroids when roid isnt roid2
|
||||
roid.explode() if roid.overlaps roid2
|
||||
5
documentation/coffee/cake_tasks.coffee
Normal file
5
documentation/coffee/cake_tasks.coffee
Normal file
@@ -0,0 +1,5 @@
|
||||
process.mixin require 'assert'
|
||||
|
||||
task 'test', 'run each of the unit tests', ->
|
||||
for test in test_files
|
||||
fs.readFile test, (err, code) -> eval coffee.compile code
|
||||
29
documentation/coffee/classes.coffee
Normal file
29
documentation/coffee/classes.coffee
Normal file
@@ -0,0 +1,29 @@
|
||||
class Animal
|
||||
move: (meters) ->
|
||||
alert @name + " moved " + meters + "m."
|
||||
|
||||
class Snake extends Animal
|
||||
constructor: (name) ->
|
||||
@name: name
|
||||
|
||||
move: ->
|
||||
alert "Slithering..."
|
||||
super 5
|
||||
|
||||
class Horse extends Animal
|
||||
constructor: (name) ->
|
||||
@name: name
|
||||
|
||||
move: ->
|
||||
alert "Galloping..."
|
||||
super 45
|
||||
|
||||
sam: new Snake "Sammy the Python"
|
||||
tom: new Horse "Tommy the Palomino"
|
||||
|
||||
sam.move()
|
||||
tom.move()
|
||||
|
||||
|
||||
|
||||
|
||||
5
documentation/coffee/comparisons.coffee
Normal file
5
documentation/coffee/comparisons.coffee
Normal file
@@ -0,0 +1,5 @@
|
||||
cholesterol: 127
|
||||
|
||||
healthy: 200 > cholesterol > 60
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ mood: greatly_improved if singing
|
||||
|
||||
if happy and knows_it
|
||||
claps_hands()
|
||||
cha_cha_cha().
|
||||
cha_cha_cha()
|
||||
|
||||
date: if friday then sue else jill.
|
||||
date: if friday then sue else jill
|
||||
|
||||
expensive ||= do_the_math()
|
||||
@@ -2,3 +2,4 @@ hi: `function() {
|
||||
return [document.title, "Hello JavaScript"].join(": ");
|
||||
}`
|
||||
|
||||
|
||||
|
||||
8
documentation/coffee/existence.coffee
Normal file
8
documentation/coffee/existence.coffee
Normal file
@@ -0,0 +1,8 @@
|
||||
solipsism: true if mind? and not world?
|
||||
|
||||
speed ?= 140
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
grade: student =>
|
||||
grade: (student) ->
|
||||
if student.excellent_work
|
||||
"A+"
|
||||
else if student.okay_stuff
|
||||
if student.tried_hard then "B" else "B-".
|
||||
if student.tried_hard then "B" else "B-"
|
||||
else
|
||||
"C"..
|
||||
"C"
|
||||
|
||||
eldest: if 24 > 21 then "Liz" else "Ike".
|
||||
eldest: if 24 > 21 then "Liz" else "Ike"
|
||||
1
documentation/coffee/expressions_assignment.coffee
Normal file
1
documentation/coffee/expressions_assignment.coffee
Normal file
@@ -0,0 +1 @@
|
||||
six: (one: 1) + (two: 2) + (three: 3)
|
||||
3
documentation/coffee/expressions_comprehension.coffee
Normal file
3
documentation/coffee/expressions_comprehension.coffee
Normal file
@@ -0,0 +1,3 @@
|
||||
# The first ten global properties.
|
||||
|
||||
globals: (name for name of window)[0...10]
|
||||
6
documentation/coffee/expressions_try.coffee
Normal file
6
documentation/coffee/expressions_try.coffee
Normal file
@@ -0,0 +1,6 @@
|
||||
alert(
|
||||
try
|
||||
nonexistent / undefined
|
||||
catch error
|
||||
"And the error is ... " + error
|
||||
)
|
||||
6
documentation/coffee/fat_arrow.coffee
Normal file
6
documentation/coffee/fat_arrow.coffee
Normal file
@@ -0,0 +1,6 @@
|
||||
Account: (customer, cart) ->
|
||||
@customer: customer
|
||||
@cart: cart
|
||||
|
||||
$('.shopping_cart').bind 'click', (event) =>
|
||||
@customer.purchase @cart
|
||||
@@ -1,2 +1,2 @@
|
||||
square: x => x * x.
|
||||
cube: x => square(x) * x.
|
||||
square: (x) -> x * x
|
||||
cube: (x) -> square(x) * x
|
||||
|
||||
5
documentation/coffee/heredocs.coffee
Normal file
5
documentation/coffee/heredocs.coffee
Normal file
@@ -0,0 +1,5 @@
|
||||
html: '''
|
||||
<strong>
|
||||
cup of coffeescript
|
||||
</strong>
|
||||
'''
|
||||
5
documentation/coffee/multiple_return_values.coffee
Normal file
5
documentation/coffee/multiple_return_values.coffee
Normal file
@@ -0,0 +1,5 @@
|
||||
weather_report: (location) ->
|
||||
# Make an Ajax request to fetch the weather...
|
||||
[location, 72, "Mostly Sunny"]
|
||||
|
||||
[city, temp, forecast]: weather_report "Berkeley, CA"
|
||||
4
documentation/coffee/object_comprehensions.coffee
Normal file
4
documentation/coffee/object_comprehensions.coffee
Normal file
@@ -0,0 +1,4 @@
|
||||
years_old: {max: 10, ida: 9, tim: 11}
|
||||
|
||||
ages: for child, age of years_old
|
||||
child + " is " + age
|
||||
13
documentation/coffee/object_extraction.coffee
Normal file
13
documentation/coffee/object_extraction.coffee
Normal file
@@ -0,0 +1,13 @@
|
||||
futurists: {
|
||||
sculptor: "Umberto Boccioni"
|
||||
painter: "Vladimir Burliuk"
|
||||
poet: {
|
||||
name: "F.T. Marinetti"
|
||||
address: [
|
||||
"Via Roma 42R"
|
||||
"Bellagio, Italy 22021"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
{poet: {name: poet, address: [street, city]}}: futurists
|
||||
@@ -1,6 +1,13 @@
|
||||
song: ["do", "re", "mi", "fa", "so"]
|
||||
|
||||
ages: {
|
||||
max: 10
|
||||
ida: 9
|
||||
tim: 11
|
||||
}
|
||||
}
|
||||
|
||||
matrix: [
|
||||
1, 0, 1
|
||||
0, 0, 1
|
||||
1, 1, 0
|
||||
]
|
||||
@@ -6,7 +6,7 @@ opposite_day: true
|
||||
number: -42 if opposite_day
|
||||
|
||||
# Functions:
|
||||
square: x => x * x.
|
||||
square: (x) -> x * x
|
||||
|
||||
# Arrays:
|
||||
list: [1, 2, 3, 4, 5]
|
||||
@@ -15,8 +15,15 @@ list: [1, 2, 3, 4, 5]
|
||||
math: {
|
||||
root: Math.sqrt
|
||||
square: square
|
||||
cube: x => x * square(x).
|
||||
cube: (x) -> x * square x
|
||||
}
|
||||
|
||||
# Splats:
|
||||
race: (winner, runners...) ->
|
||||
print winner, runners
|
||||
|
||||
# Existence:
|
||||
alert "I knew it!" if elvis?
|
||||
|
||||
# Array comprehensions:
|
||||
cubed_list: math.cube(num) for num in list.
|
||||
cubed_list: math.cube num for num in list
|
||||
|
||||
4
documentation/coffee/parallel_assignment.coffee
Normal file
4
documentation/coffee/parallel_assignment.coffee
Normal file
@@ -0,0 +1,4 @@
|
||||
bait: 1000
|
||||
and_switch: 0
|
||||
|
||||
[bait, and_switch]: [and_switch, bait]
|
||||
2
documentation/coffee/prototypes.coffee
Normal file
2
documentation/coffee/prototypes.coffee
Normal file
@@ -0,0 +1,2 @@
|
||||
String::dasherize: ->
|
||||
this.replace(/_/g, "-")
|
||||
6
documentation/coffee/range_comprehensions.coffee
Normal file
6
documentation/coffee/range_comprehensions.coffee
Normal file
@@ -0,0 +1,6 @@
|
||||
countdown: num for num in [10..1]
|
||||
|
||||
egg_delivery: ->
|
||||
for i in [0...eggs.length] by 12
|
||||
dozen_eggs: eggs[i...i+12]
|
||||
deliver new egg_carton(dozen)
|
||||
@@ -1,5 +1,5 @@
|
||||
num: 1
|
||||
change_numbers: =>
|
||||
num: 2
|
||||
new_num: 3.
|
||||
change_numbers: ->
|
||||
new_num: -1
|
||||
num: 10
|
||||
new_num: change_numbers()
|
||||
@@ -1,2 +1,6 @@
|
||||
nums: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
three_to_six: nums[3, 6]
|
||||
numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
|
||||
three_to_six: numbers[3..6]
|
||||
|
||||
numbers_copy: numbers[0...numbers.length]
|
||||
|
||||
|
||||
1
documentation/coffee/soaks.coffee
Normal file
1
documentation/coffee/soaks.coffee
Normal file
@@ -0,0 +1 @@
|
||||
lottery.draw_winner()?.address?.zipcode
|
||||
25
documentation/coffee/splats.coffee
Normal file
25
documentation/coffee/splats.coffee
Normal file
@@ -0,0 +1,25 @@
|
||||
gold: silver: the_field: "unknown"
|
||||
|
||||
award_medals: (first, second, rest...) ->
|
||||
gold: first
|
||||
silver: second
|
||||
the_field: rest
|
||||
|
||||
contenders: [
|
||||
"Michael Phelps"
|
||||
"Liu Xiang"
|
||||
"Yao Ming"
|
||||
"Allyson Felix"
|
||||
"Shawn Johnson"
|
||||
"Roman Sebrle"
|
||||
"Guo Jingjing"
|
||||
"Tyson Gay"
|
||||
"Asafa Powell"
|
||||
"Usain Bolt"
|
||||
]
|
||||
|
||||
award_medals contenders...
|
||||
|
||||
alert "Gold: " + gold
|
||||
alert "Silver: " + silver
|
||||
alert "The Field: " + the_field
|
||||
5
documentation/coffee/splices.coffee
Normal file
5
documentation/coffee/splices.coffee
Normal file
@@ -0,0 +1,5 @@
|
||||
numbers: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
|
||||
numbers[3..6]: [-3, -4, -5, -6]
|
||||
|
||||
|
||||
@@ -5,3 +5,4 @@ to interest me on shore, I thought I would sail
|
||||
about a little and see the watery part of the
|
||||
world..."
|
||||
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
Animal: => .
|
||||
Animal.prototype.move: meters =>
|
||||
alert(this.name + " moved " + meters + "m.").
|
||||
|
||||
Snake: name => this.name: name.
|
||||
Snake extends Animal
|
||||
Snake.prototype.move: =>
|
||||
alert("Slithering...")
|
||||
super(5).
|
||||
|
||||
Horse: name => this.name: name.
|
||||
Horse extends Animal
|
||||
Horse.prototype.move: =>
|
||||
alert("Galloping...")
|
||||
super(45).
|
||||
|
||||
sam: new Snake("Sammy the Python")
|
||||
tom: new Horse("Tommy the Palomino")
|
||||
|
||||
sam.move()
|
||||
tom.move()
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
switch day
|
||||
when "Tuesday" then eat_breakfast()
|
||||
when "Wednesday" then go_to_the_park()
|
||||
when "Saturday"
|
||||
if day is bingo_day
|
||||
go_to_bingo()
|
||||
go_dancing().
|
||||
when "Sunday" then go_to_church()
|
||||
else go_to_work().
|
||||
when "Mon" then go_to_work()
|
||||
when "Tue" then go_to_the_park()
|
||||
when "Thu" then go_ice_fishing()
|
||||
when "Fri", "Sat"
|
||||
if day is bingo_day
|
||||
go_to_bingo()
|
||||
go_dancing()
|
||||
when "Sun" then go_to_church()
|
||||
else go_to_work()
|
||||
@@ -2,6 +2,6 @@ try
|
||||
all_hell_breaks_loose()
|
||||
cats_and_dogs_living_together()
|
||||
catch error
|
||||
print(error)
|
||||
print error
|
||||
finally
|
||||
clean_up().
|
||||
clean_up()
|
||||
@@ -1,5 +1,10 @@
|
||||
while demand > supply
|
||||
sell()
|
||||
restock().
|
||||
# Econ 101
|
||||
if this.studying_economics
|
||||
while supply > demand then buy()
|
||||
while supply < demand then sell()
|
||||
|
||||
while supply > demand then buy().
|
||||
# Nursery Rhyme
|
||||
num: 6
|
||||
lyrics: while num -= 1
|
||||
num + " little monkeys, jumping on the bed.
|
||||
One fell out and bumped his head."
|
||||
|
||||
@@ -1,147 +0,0 @@
|
||||
pre.amy .PolymorphicVariants {
|
||||
color: #60B0FF;
|
||||
font-style: italic;
|
||||
}
|
||||
pre.amy .KeywordDecorator {
|
||||
color: #D0D0FF;
|
||||
}
|
||||
pre.amy .Punctuation {
|
||||
color: #805080;
|
||||
}
|
||||
pre.amy .InheritedClass {
|
||||
}
|
||||
pre.amy .InvalidDepricated {
|
||||
background-color: #CC66FF;
|
||||
color: #200020;
|
||||
}
|
||||
pre.amy .LibraryVariable {
|
||||
}
|
||||
pre.amy .TokenReferenceOcamlyacc {
|
||||
color: #3CB0D0;
|
||||
}
|
||||
pre.amy .Storage {
|
||||
color: #B0FFF0;
|
||||
}
|
||||
pre.amy .KeywordOperator {
|
||||
color: #A0A0FF;
|
||||
}
|
||||
pre.amy .CharacterConstant {
|
||||
color: #666666;
|
||||
}
|
||||
pre.amy .line-numbers {
|
||||
background-color: #800000;
|
||||
color: #000000;
|
||||
}
|
||||
pre.amy .ClassName {
|
||||
color: #70E080;
|
||||
}
|
||||
pre.amy .Int64Constant {
|
||||
font-style: italic;
|
||||
}
|
||||
pre.amy .NonTerminalReferenceOcamlyacc {
|
||||
color: #C0F0F0;
|
||||
}
|
||||
pre.amy .TokenDefinitionOcamlyacc {
|
||||
color: #3080A0;
|
||||
}
|
||||
pre.amy .ClassType {
|
||||
color: #70E0A0;
|
||||
}
|
||||
pre.amy .ControlKeyword {
|
||||
color: #80A0FF;
|
||||
}
|
||||
pre.amy .LineNumberDirectives {
|
||||
text-decoration: underline;
|
||||
color: #C080C0;
|
||||
}
|
||||
pre.amy .FloatingPointConstant {
|
||||
text-decoration: underline;
|
||||
}
|
||||
pre.amy .Int32Constant {
|
||||
font-weight: bold;
|
||||
}
|
||||
pre.amy .TagName {
|
||||
color: #009090;
|
||||
}
|
||||
pre.amy .ModuleTypeDefinitions {
|
||||
text-decoration: underline;
|
||||
color: #B000B0;
|
||||
}
|
||||
pre.amy .Integer {
|
||||
color: #7090B0;
|
||||
}
|
||||
pre.amy .Camlp4TempParser {
|
||||
}
|
||||
pre.amy .InvalidIllegal {
|
||||
font-weight: bold;
|
||||
background-color: #FFFF00;
|
||||
color: #400080;
|
||||
}
|
||||
pre.amy .LibraryConstant {
|
||||
background-color: #200020;
|
||||
}
|
||||
pre.amy .ModuleDefinitions {
|
||||
color: #B000B0;
|
||||
}
|
||||
pre.amy .Variants {
|
||||
color: #60B0FF;
|
||||
}
|
||||
pre.amy .CompilerDirectives {
|
||||
color: #C080C0;
|
||||
}
|
||||
pre.amy .FloatingPointInfixOperator {
|
||||
text-decoration: underline;
|
||||
}
|
||||
pre.amy .BuiltInConstant1 {
|
||||
}
|
||||
pre.amy {
|
||||
background-color: #200020;
|
||||
color: #D0D0FF;
|
||||
}
|
||||
pre.amy .FunctionArgument {
|
||||
color: #80B0B0;
|
||||
}
|
||||
pre.amy .FloatingPointPrefixOperator {
|
||||
text-decoration: underline;
|
||||
}
|
||||
pre.amy .NativeintConstant {
|
||||
font-weight: bold;
|
||||
}
|
||||
pre.amy .BuiltInConstant {
|
||||
color: #707090;
|
||||
}
|
||||
pre.amy .BooleanConstant {
|
||||
color: #8080A0;
|
||||
}
|
||||
pre.amy .LibraryClassType {
|
||||
}
|
||||
pre.amy .TagAttribute {
|
||||
}
|
||||
pre.amy .Keyword {
|
||||
color: #A080FF;
|
||||
}
|
||||
pre.amy .UserDefinedConstant {
|
||||
}
|
||||
pre.amy .String {
|
||||
color: #999999;
|
||||
}
|
||||
pre.amy .Camlp4Code {
|
||||
background-color: #350060;
|
||||
}
|
||||
pre.amy .NonTerminalDefinitionOcamlyacc {
|
||||
color: #90E0E0;
|
||||
}
|
||||
pre.amy .FunctionName {
|
||||
color: #50A0A0;
|
||||
}
|
||||
pre.amy .SupportModules {
|
||||
color: #A00050;
|
||||
}
|
||||
pre.amy .Variable {
|
||||
color: #008080;
|
||||
}
|
||||
pre.amy .Comment {
|
||||
background-color: #200020;
|
||||
color: #404080;
|
||||
font-style: italic;
|
||||
}
|
||||
@@ -1,29 +1,29 @@
|
||||
body {
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
background: #f3f3f9;
|
||||
color: #191933;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
}
|
||||
div.container {
|
||||
width: 850px;
|
||||
margin: 50px 0 50px 50px;
|
||||
width: 950px;
|
||||
margin: 100px 0 50px 50px;
|
||||
}
|
||||
p {
|
||||
padding-left: 13px;
|
||||
width: 625px;
|
||||
}
|
||||
a {
|
||||
color: #000055;
|
||||
}
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
padding-left: 13px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
br.clear {
|
||||
height: 0;
|
||||
clear: both;
|
||||
}
|
||||
ul {
|
||||
padding-left: 20px;
|
||||
}
|
||||
b.header {
|
||||
color: #000055;
|
||||
display: block;
|
||||
@@ -31,7 +31,7 @@ b.header {
|
||||
font-size: 16px;
|
||||
}
|
||||
li {
|
||||
margin-bottom: 7px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
table {
|
||||
margin: 16px 0 0 13px; padding: 0;
|
||||
@@ -43,11 +43,13 @@ table {
|
||||
td {
|
||||
padding: 9px 15px 9px 0;
|
||||
}
|
||||
code, pre, tt {
|
||||
code, pre, tt, textarea {
|
||||
font-family: Monaco, Consolas, "Lucida Console", monospace;
|
||||
font-size: 12px;
|
||||
line-height: 18px;
|
||||
color: #191955;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
tt {
|
||||
background: #f8f8ff;
|
||||
@@ -61,10 +63,15 @@ code, pre, tt {
|
||||
padding: 3px 0 3px 12px;
|
||||
font-size: 12px;
|
||||
}
|
||||
pre.no_bar {
|
||||
border-left: 0;
|
||||
margin-left: 0;
|
||||
padding-left: 0;
|
||||
}
|
||||
div.code {
|
||||
position: relative;
|
||||
border: 1px solid #cacaca;
|
||||
background: #fff;
|
||||
background: #fafaff;
|
||||
padding: 7px 0 10px 0;
|
||||
-moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px;
|
||||
-webkit-box-shadow: 0px 0px 7px #cacaca;
|
||||
@@ -73,13 +80,187 @@ div.code {
|
||||
position: absolute;
|
||||
right: 8px; bottom: 8px;
|
||||
}
|
||||
div.code pre {
|
||||
div.code pre, div.code textarea {
|
||||
float: left;
|
||||
width: 410px;
|
||||
width: 450px;
|
||||
background: #fafaff;
|
||||
border-left: 1px dotted #559;
|
||||
padding: 0 0 0 12px;
|
||||
margin: 0;
|
||||
}
|
||||
div.code pre:first-child {
|
||||
border-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
#fadeout {
|
||||
z-index: 50;
|
||||
position: fixed;
|
||||
left: 0; top: 0; right: 0;
|
||||
height: 100px;
|
||||
background: -webkit-gradient(linear, left top, left bottom, from(rgba(255, 255, 255, 255)), to(rgba(255, 255, 255, 0)));
|
||||
background: -moz-linear-gradient(top, rgba(255, 255, 255, 255), rgba(255, 255, 255, 0));
|
||||
}
|
||||
|
||||
#flybar {
|
||||
position: fixed;
|
||||
z-index: 100;
|
||||
height: 50px;
|
||||
left: 40px; right: 40px; top: 25px;
|
||||
background: #ddd;
|
||||
padding-left: 235px;
|
||||
background: -webkit-gradient(linear, left top, left bottom, from(#f5f5f5), to(#d0d0d0));
|
||||
background: -moz-linear-gradient(top, #f5f5f5, #d0d0d0);
|
||||
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#F5F5F5', EndColorStr='#D0D0D0');
|
||||
-webkit-border-radius: 20px; -moz-border-radius: 20px; border-radius: 20px;
|
||||
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
|
||||
}
|
||||
#logo {
|
||||
display: block;
|
||||
width: 215px; height: 50px;
|
||||
background: url('../images/logo.png');
|
||||
position: absolute;
|
||||
top: 0px; left: 10px;
|
||||
}
|
||||
#error {
|
||||
position: absolute;
|
||||
-webkit-border-radius: 6px; -moz-border-radius: 6px; border-radius: 6px;
|
||||
right: 15px; top: 15px; left: 565px;
|
||||
height: 15px;
|
||||
padding: 2px 5px;
|
||||
background: #fdcdcc;
|
||||
color: #864544;
|
||||
border: 1px solid #864544;
|
||||
font: 10px/15px Arial;
|
||||
overflow: hidden;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
.navigation {
|
||||
height: 50px;
|
||||
font: bold 11px/50px Arial;
|
||||
text-transform: uppercase;
|
||||
position: relative;
|
||||
float: left;
|
||||
padding: 0 20px;
|
||||
border: 1px solid #bbb;
|
||||
border-top: 0; border-bottom: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
body.full_screen .navigation {
|
||||
position: static;
|
||||
}
|
||||
.navigation.try {
|
||||
border-left: 0;
|
||||
}
|
||||
.navigation:hover,
|
||||
.navigation.active {
|
||||
background: #d0d0d0;
|
||||
background: -webkit-gradient(linear, left top, left bottom, from(#f0f0f0), to(#c0c0c0));
|
||||
background: -moz-linear-gradient(top, #f0f0f0, #c0c0c0);
|
||||
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#F0F0F0', EndColorStr='#C0C0C0');
|
||||
}
|
||||
.navigation .contents {
|
||||
display: none;
|
||||
position: absolute;
|
||||
background: #fff;
|
||||
top: 50px; left: 0;
|
||||
padding: 5px 0;
|
||||
-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px;
|
||||
-webkit-border-top-left-radius: 0; -moz-border-radius-topleft: 0;
|
||||
-webkit-border-top-right-radius: 0; -moz-border-radius-topright: 0;
|
||||
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
|
||||
}
|
||||
.navigation.active .contents {
|
||||
display: block;
|
||||
}
|
||||
.navigation .contents.repl_wrapper {
|
||||
left: -162px;
|
||||
width: 700px;
|
||||
padding: 0;
|
||||
}
|
||||
body.full_screen .navigation .contents.repl_wrapper {
|
||||
position: fixed;
|
||||
width: auto; height: auto;
|
||||
left: 60px; top: 75px; right: 60px; bottom: 30px;
|
||||
}
|
||||
.navigation .contents.repl_wrapper .code {
|
||||
-webkit-box-shadow: none; -moz-box-shadow: none;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
position: static;
|
||||
}
|
||||
body.full_screen .navigation .contents.repl_wrapper .code {
|
||||
height: 100%;
|
||||
padding: 0; margin: 0;
|
||||
}
|
||||
.navigation .code button {
|
||||
bottom: 10px;
|
||||
text-transform: none;
|
||||
}
|
||||
.navigation .full_screen, .navigation .minimize {
|
||||
right: auto;
|
||||
left: 10px;
|
||||
display: none;
|
||||
}
|
||||
body.minimized .full_screen, body.full_screen .minimize {
|
||||
display: inline;
|
||||
}
|
||||
.navigation .contents a {
|
||||
display: block;
|
||||
width: 300px;
|
||||
text-transform: none;
|
||||
text-decoration: none;
|
||||
font-weight: normal;
|
||||
height: 12px;
|
||||
line-height: 12px;
|
||||
padding: 4px 10px;
|
||||
}
|
||||
.navigation .contents a:hover {
|
||||
background: #f0f0f0;
|
||||
}
|
||||
|
||||
.bookmark {
|
||||
display: block;
|
||||
width: 0; height: 0;
|
||||
position: relative;
|
||||
top: -90px;
|
||||
}
|
||||
|
||||
#repl_source, #repl_results {
|
||||
background: transparent;
|
||||
outline: none;
|
||||
margin: 5px 0 20px;
|
||||
}
|
||||
#repl_source_wrap {
|
||||
margin-left: 5px;
|
||||
height: 250px;
|
||||
width: 307px;
|
||||
position: relative;
|
||||
float: left;
|
||||
}
|
||||
#repl_source {
|
||||
width: 96%;
|
||||
height: 100%;
|
||||
border: 0;
|
||||
resize: none;
|
||||
}
|
||||
#repl_results {
|
||||
font-family: Monaco, Consolas, "Lucida Console", monospace;
|
||||
text-transform: none;
|
||||
font-weight: normal;
|
||||
height: 260px;
|
||||
margin-bottom: 25px;
|
||||
overflow-y: auto;
|
||||
width: 370px;
|
||||
}
|
||||
body.full_screen #repl_results, body.full_screen #repl_source_wrap {
|
||||
width: auto; height: auto;
|
||||
position: absolute;
|
||||
margin-bottom: 0;
|
||||
top: 10px; left: 10px; right: 10px; bottom: 40px;
|
||||
}
|
||||
body.full_screen #repl_source_wrap {
|
||||
right: 50%;
|
||||
}
|
||||
body.full_screen #repl_results {
|
||||
left: 50%;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ pre.idle .LibraryConstant {
|
||||
color: #A535AE;
|
||||
}
|
||||
pre.idle .FunctionArgument {
|
||||
color: #0076ad;
|
||||
}
|
||||
pre.idle .BuiltInConstant {
|
||||
color: #A535AE;
|
||||
@@ -56,6 +57,7 @@ pre.idle .FunctionName {
|
||||
color: #21439C;
|
||||
}
|
||||
pre.idle .Variable {
|
||||
color: #A535AE;
|
||||
}
|
||||
pre.idle .Comment {
|
||||
color: #919191;
|
||||
|
||||
BIN
documentation/images/favicon.ico
Normal file
BIN
documentation/images/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
BIN
documentation/images/logo.png
Normal file
BIN
documentation/images/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.9 KiB |
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,8 @@
|
||||
(function(){
|
||||
var volume;
|
||||
if (ignition === true) {
|
||||
launch();
|
||||
}
|
||||
var volume;
|
||||
if (band !== spinal_tap) {
|
||||
volume = 10;
|
||||
}
|
||||
@@ -10,4 +10,5 @@
|
||||
let_the_wild_rumpus_begin();
|
||||
}
|
||||
car.speed < speed_limit ? accelerate() : null;
|
||||
})();
|
||||
print("My name is " + this.name);
|
||||
})();
|
||||
|
||||
8
documentation/js/arguments.js
Normal file
8
documentation/js/arguments.js
Normal file
@@ -0,0 +1,8 @@
|
||||
(function(){
|
||||
var backwards;
|
||||
backwards = function backwards() {
|
||||
arguments = Array.prototype.slice.call(arguments, 0);
|
||||
return alert(arguments.reverse());
|
||||
};
|
||||
backwards("stairway", "to", "heaven");
|
||||
})();
|
||||
@@ -1,21 +1,26 @@
|
||||
(function(){
|
||||
|
||||
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, food, lunch, roid, roid2;
|
||||
// Eat lunch.
|
||||
var lunch;
|
||||
var __a = ['toast', 'cheese', 'wine'];
|
||||
var __d = [];
|
||||
for (var __b=0, __c=__a.length; __b<__c; __b++) {
|
||||
var food = __a[__b];
|
||||
__d[__b] = food.eat();
|
||||
lunch = (function() {
|
||||
_a = []; _b = ['toast', 'cheese', 'wine'];
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
food = _b[_c];
|
||||
_a.push(eat(food));
|
||||
}
|
||||
return _a;
|
||||
}).call(this);
|
||||
// Naive collision detection.
|
||||
_e = asteroids;
|
||||
for (_f = 0, _g = _e.length; _f < _g; _f++) {
|
||||
roid = _e[_f];
|
||||
_h = asteroids;
|
||||
for (_i = 0, _j = _h.length; _i < _j; _i++) {
|
||||
roid2 = _h[_i];
|
||||
if (roid !== roid2) {
|
||||
if (roid.overlaps(roid2)) {
|
||||
roid.explode();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lunch = __d;
|
||||
// Zebra-stripe a table.
|
||||
var __e = table;
|
||||
var __h = [];
|
||||
for (var __f=0, __g=__e.length; __f<__g; __f++) {
|
||||
var row = __e[__f];
|
||||
var i = __f;
|
||||
__h[__f] = i % 2 === 0 ? highlight(row) : null;
|
||||
}
|
||||
__h;
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
(function(){
|
||||
var greeting = "Hello CoffeeScript";
|
||||
var difficulty = 0.5;
|
||||
})();
|
||||
var difficulty, greeting;
|
||||
greeting = "Hello CoffeeScript";
|
||||
difficulty = 0.5;
|
||||
})();
|
||||
|
||||
14
documentation/js/cake_tasks.js
Normal file
14
documentation/js/cake_tasks.js
Normal file
@@ -0,0 +1,14 @@
|
||||
(function(){
|
||||
process.mixin(require('assert'));
|
||||
task('test', 'run each of the unit tests', function() {
|
||||
var _a, _b, _c, _d, test;
|
||||
_a = []; _b = test_files;
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
test = _b[_c];
|
||||
_a.push(fs.readFile(test, function(err, code) {
|
||||
return eval(coffee.compile(code));
|
||||
}));
|
||||
}
|
||||
return _a;
|
||||
});
|
||||
})();
|
||||
36
documentation/js/classes.js
Normal file
36
documentation/js/classes.js
Normal file
@@ -0,0 +1,36 @@
|
||||
(function(){
|
||||
var Animal, Horse, Snake, sam, tom;
|
||||
var __extends = function(child, parent) {
|
||||
var ctor = function(){ };
|
||||
ctor.prototype = parent.prototype;
|
||||
child.__superClass__ = parent.prototype;
|
||||
child.prototype = new ctor();
|
||||
child.prototype.constructor = child;
|
||||
};
|
||||
Animal = function Animal() { };
|
||||
Animal.prototype.move = function move(meters) {
|
||||
return alert(this.name + " moved " + meters + "m.");
|
||||
};
|
||||
Snake = function Snake(name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
};
|
||||
__extends(Snake, Animal);
|
||||
Snake.prototype.move = function move() {
|
||||
alert("Slithering...");
|
||||
return Snake.__superClass__.move.call(this, 5);
|
||||
};
|
||||
Horse = function Horse(name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
};
|
||||
__extends(Horse, Animal);
|
||||
Horse.prototype.move = function move() {
|
||||
alert("Galloping...");
|
||||
return Horse.__superClass__.move.call(this, 45);
|
||||
};
|
||||
sam = new Snake("Sammy the Python");
|
||||
tom = new Horse("Tommy the Palomino");
|
||||
sam.move();
|
||||
tom.move();
|
||||
})();
|
||||
5
documentation/js/comparisons.js
Normal file
5
documentation/js/comparisons.js
Normal file
@@ -0,0 +1,5 @@
|
||||
(function(){
|
||||
var cholesterol, healthy;
|
||||
cholesterol = 127;
|
||||
healthy = (200 > cholesterol) && (cholesterol > 60);
|
||||
})();
|
||||
@@ -1,5 +1,5 @@
|
||||
(function(){
|
||||
var mood;
|
||||
var date, expensive, mood;
|
||||
if (singing) {
|
||||
mood = greatly_improved;
|
||||
}
|
||||
@@ -7,6 +7,6 @@
|
||||
claps_hands();
|
||||
cha_cha_cha();
|
||||
}
|
||||
var date = friday ? sue : jill;
|
||||
date = friday ? sue : jill;
|
||||
expensive = expensive || do_the_math();
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
(function(){
|
||||
var hi = function() {
|
||||
var hi;
|
||||
hi = function() {
|
||||
return [document.title, "Hello JavaScript"].join(": ");
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
||||
7
documentation/js/existence.js
Normal file
7
documentation/js/existence.js
Normal file
@@ -0,0 +1,7 @@
|
||||
(function(){
|
||||
var solipsism, speed;
|
||||
if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) {
|
||||
solipsism = true;
|
||||
}
|
||||
speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140;
|
||||
})();
|
||||
@@ -1,5 +1,6 @@
|
||||
(function(){
|
||||
var grade = function(student) {
|
||||
var eldest, grade;
|
||||
grade = function grade(student) {
|
||||
if (student.excellent_work) {
|
||||
return "A+";
|
||||
} else if (student.okay_stuff) {
|
||||
@@ -8,5 +9,5 @@
|
||||
return "C";
|
||||
}
|
||||
};
|
||||
var eldest = 24 > 21 ? "Liz" : "Ike";
|
||||
})();
|
||||
eldest = 24 > 21 ? "Liz" : "Ike";
|
||||
})();
|
||||
|
||||
4
documentation/js/expressions_assignment.js
Normal file
4
documentation/js/expressions_assignment.js
Normal file
@@ -0,0 +1,4 @@
|
||||
(function(){
|
||||
var one, six, three, two;
|
||||
six = ((one = 1)) + ((two = 2)) + ((three = 3));
|
||||
})();
|
||||
12
documentation/js/expressions_comprehension.js
Normal file
12
documentation/js/expressions_comprehension.js
Normal file
@@ -0,0 +1,12 @@
|
||||
(function(){
|
||||
var _a, _b, globals, name;
|
||||
var __hasProp = Object.prototype.hasOwnProperty;
|
||||
// The first ten global properties.
|
||||
globals = (function() {
|
||||
_a = []; _b = window;
|
||||
for (name in _b) { if (__hasProp.call(_b, name)) {
|
||||
_a.push(name);
|
||||
}}
|
||||
return _a;
|
||||
}).call(this).slice(0, 10);
|
||||
})();
|
||||
9
documentation/js/expressions_try.js
Normal file
9
documentation/js/expressions_try.js
Normal file
@@ -0,0 +1,9 @@
|
||||
(function(){
|
||||
alert((function() {
|
||||
try {
|
||||
return nonexistent / undefined;
|
||||
} catch (error) {
|
||||
return "And the error is ... " + error;
|
||||
}
|
||||
}).call(this));
|
||||
})();
|
||||
15
documentation/js/fat_arrow.js
Normal file
15
documentation/js/fat_arrow.js
Normal file
@@ -0,0 +1,15 @@
|
||||
(function(){
|
||||
var Account;
|
||||
Account = function Account(customer, cart) {
|
||||
this.customer = customer;
|
||||
this.cart = cart;
|
||||
return $('.shopping_cart').bind('click', (function(__this) {
|
||||
var __func = function(event) {
|
||||
return this.customer.purchase(this.cart);
|
||||
};
|
||||
return (function() {
|
||||
return __func.apply(__this, arguments);
|
||||
});
|
||||
})(this));
|
||||
};
|
||||
})();
|
||||
@@ -1,8 +1,9 @@
|
||||
(function(){
|
||||
var square = function(x) {
|
||||
var cube, square;
|
||||
square = function square(x) {
|
||||
return x * x;
|
||||
};
|
||||
var cube = function(x) {
|
||||
cube = function cube(x) {
|
||||
return square(x) * x;
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
||||
4
documentation/js/heredocs.js
Normal file
4
documentation/js/heredocs.js
Normal file
@@ -0,0 +1,4 @@
|
||||
(function(){
|
||||
var html;
|
||||
html = "<strong>\n cup of coffeescript\n</strong>";
|
||||
})();
|
||||
11
documentation/js/multiple_return_values.js
Normal file
11
documentation/js/multiple_return_values.js
Normal file
@@ -0,0 +1,11 @@
|
||||
(function(){
|
||||
var _a, city, forecast, temp, weather_report;
|
||||
weather_report = function weather_report(location) {
|
||||
// Make an Ajax request to fetch the weather...
|
||||
return [location, 72, "Mostly Sunny"];
|
||||
};
|
||||
_a = weather_report("Berkeley, CA");
|
||||
city = _a[0];
|
||||
temp = _a[1];
|
||||
forecast = _a[2];
|
||||
})();
|
||||
17
documentation/js/object_comprehensions.js
Normal file
17
documentation/js/object_comprehensions.js
Normal file
@@ -0,0 +1,17 @@
|
||||
(function(){
|
||||
var _a, _b, age, ages, child, years_old;
|
||||
var __hasProp = Object.prototype.hasOwnProperty;
|
||||
years_old = {
|
||||
max: 10,
|
||||
ida: 9,
|
||||
tim: 11
|
||||
};
|
||||
ages = (function() {
|
||||
_a = []; _b = years_old;
|
||||
for (child in _b) { if (__hasProp.call(_b, child)) {
|
||||
age = _b[child];
|
||||
_a.push(child + " is " + age);
|
||||
}}
|
||||
return _a;
|
||||
}).call(this);
|
||||
})();
|
||||
17
documentation/js/object_extraction.js
Normal file
17
documentation/js/object_extraction.js
Normal file
@@ -0,0 +1,17 @@
|
||||
(function(){
|
||||
var _a, _b, _c, city, futurists, poet, street;
|
||||
futurists = {
|
||||
sculptor: "Umberto Boccioni",
|
||||
painter: "Vladimir Burliuk",
|
||||
poet: {
|
||||
name: "F.T. Marinetti",
|
||||
address: ["Via Roma 42R", "Bellagio, Italy 22021"]
|
||||
}
|
||||
};
|
||||
_a = futurists;
|
||||
_b = _a.poet;
|
||||
poet = _b.name;
|
||||
_c = _b.address;
|
||||
street = _c[0];
|
||||
city = _c[1];
|
||||
})();
|
||||
@@ -1,8 +1,10 @@
|
||||
(function(){
|
||||
var song = ["do", "re", "mi", "fa", "so"];
|
||||
var ages = {
|
||||
var ages, matrix, song;
|
||||
song = ["do", "re", "mi", "fa", "so"];
|
||||
ages = {
|
||||
max: 10,
|
||||
ida: 9,
|
||||
tim: 11
|
||||
};
|
||||
})();
|
||||
matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0];
|
||||
})();
|
||||
|
||||
@@ -1,33 +1,43 @@
|
||||
(function(){
|
||||
|
||||
var _a, _b, _c, _d, cubed_list, list, math, num, number, opposite_day, race, square;
|
||||
// Assignment:
|
||||
var number = 42;
|
||||
var opposite_day = true;
|
||||
number = 42;
|
||||
opposite_day = true;
|
||||
// Conditions:
|
||||
if (opposite_day) {
|
||||
number = -42;
|
||||
}
|
||||
// Functions:
|
||||
var square = function(x) {
|
||||
square = function square(x) {
|
||||
return x * x;
|
||||
};
|
||||
// Arrays:
|
||||
var list = [1, 2, 3, 4, 5];
|
||||
list = [1, 2, 3, 4, 5];
|
||||
// Objects:
|
||||
var math = {
|
||||
math = {
|
||||
root: Math.sqrt,
|
||||
square: square,
|
||||
cube: function(x) {
|
||||
cube: function cube(x) {
|
||||
return x * square(x);
|
||||
}
|
||||
};
|
||||
// Array comprehensions:
|
||||
var cubed_list;
|
||||
var __a = list;
|
||||
var __d = [];
|
||||
for (var __b=0, __c=__a.length; __b<__c; __b++) {
|
||||
var num = __a[__b];
|
||||
__d[__b] = math.cube(num);
|
||||
// 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!");
|
||||
}
|
||||
cubed_list = __d;
|
||||
})();
|
||||
// Array comprehensions:
|
||||
cubed_list = (function() {
|
||||
_a = []; _b = list;
|
||||
for (_c = 0, _d = _b.length; _c < _d; _c++) {
|
||||
num = _b[_c];
|
||||
_a.push(math.cube(num));
|
||||
}
|
||||
return _a;
|
||||
}).call(this);
|
||||
})();
|
||||
|
||||
8
documentation/js/parallel_assignment.js
Normal file
8
documentation/js/parallel_assignment.js
Normal file
@@ -0,0 +1,8 @@
|
||||
(function(){
|
||||
var _a, and_switch, bait;
|
||||
bait = 1000;
|
||||
and_switch = 0;
|
||||
_a = [and_switch, bait];
|
||||
bait = _a[0];
|
||||
and_switch = _a[1];
|
||||
})();
|
||||
5
documentation/js/prototypes.js
vendored
Normal file
5
documentation/js/prototypes.js
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
(function(){
|
||||
String.prototype.dasherize = function dasherize() {
|
||||
return this.replace(/_/g, "-");
|
||||
};
|
||||
})();
|
||||
21
documentation/js/range_comprehensions.js
Normal file
21
documentation/js/range_comprehensions.js
Normal file
@@ -0,0 +1,21 @@
|
||||
(function(){
|
||||
var _a, _b, _c, _d, _e, countdown, egg_delivery, num;
|
||||
countdown = (function() {
|
||||
_a = []; _d = 10; _e = 1;
|
||||
for (_c = 0, num = _d; (_d <= _e ? num <= _e : num >= _e); (_d <= _e ? num += 1 : num -= 1), _c++) {
|
||||
_a.push(num);
|
||||
}
|
||||
return _a;
|
||||
}).call(this);
|
||||
egg_delivery = function egg_delivery() {
|
||||
var _f, _g, _h, _i, _j, dozen_eggs, i;
|
||||
_f = []; _i = 0; _j = eggs.length;
|
||||
for (_h = 0, i = _i; (_i <= _j ? i < _j : i > _j); (_i <= _j ? i += 12 : i -= 12), _h++) {
|
||||
_f.push((function() {
|
||||
dozen_eggs = eggs.slice(i, i + 12);
|
||||
return deliver(new egg_carton(dozen));
|
||||
}).call(this));
|
||||
}
|
||||
return _f;
|
||||
};
|
||||
})();
|
||||
@@ -1,9 +1,10 @@
|
||||
(function(){
|
||||
var num = 1;
|
||||
var change_numbers = function() {
|
||||
num = 2;
|
||||
var new_num = 3;
|
||||
return new_num;
|
||||
var change_numbers, new_num, num;
|
||||
num = 1;
|
||||
change_numbers = function change_numbers() {
|
||||
var new_num;
|
||||
new_num = -1;
|
||||
return num = 10;
|
||||
};
|
||||
var new_num = change_numbers();
|
||||
})();
|
||||
new_num = change_numbers();
|
||||
})();
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
(function(){
|
||||
var nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
var three_to_six = nums.slice(3, 6 + 1);
|
||||
})();
|
||||
var numbers, numbers_copy, three_to_six;
|
||||
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
three_to_six = numbers.slice(3, 6 + 1);
|
||||
numbers_copy = numbers.slice(0, numbers.length);
|
||||
})();
|
||||
|
||||
4
documentation/js/soaks.js
Normal file
4
documentation/js/soaks.js
Normal file
@@ -0,0 +1,4 @@
|
||||
(function(){
|
||||
var _a;
|
||||
(_a = lottery.draw_winner()) == undefined ? undefined : _a.address == undefined ? undefined : _a.address.zipcode;
|
||||
})();
|
||||
16
documentation/js/splats.js
Normal file
16
documentation/js/splats.js
Normal file
@@ -0,0 +1,16 @@
|
||||
(function(){
|
||||
var award_medals, contenders, gold, silver, the_field;
|
||||
gold = (silver = (the_field = "unknown"));
|
||||
award_medals = function award_medals(first, second) {
|
||||
var rest;
|
||||
rest = Array.prototype.slice.call(arguments, 2);
|
||||
gold = first;
|
||||
silver = second;
|
||||
return the_field = rest;
|
||||
};
|
||||
contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"];
|
||||
award_medals.apply(this, contenders);
|
||||
alert("Gold: " + gold);
|
||||
alert("Silver: " + silver);
|
||||
alert("The Field: " + the_field);
|
||||
})();
|
||||
5
documentation/js/splices.js
Normal file
5
documentation/js/splices.js
Normal file
@@ -0,0 +1,5 @@
|
||||
(function(){
|
||||
var numbers;
|
||||
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
numbers.splice.apply(numbers, [3, 6 - 3 + 1].concat([-3, -4, -5, -6]));
|
||||
})();
|
||||
@@ -1,8 +1,9 @@
|
||||
(function(){
|
||||
var moby_dick = "Call me Ishmael. Some years ago -- \
|
||||
var moby_dick;
|
||||
moby_dick = "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...";
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
(function(){
|
||||
var Animal = function() {
|
||||
};
|
||||
Animal.prototype.move = function(meters) {
|
||||
return alert(this.name + " moved " + meters + "m.");
|
||||
};
|
||||
var Snake = function(name) {
|
||||
this.name = name;
|
||||
return this.name;
|
||||
};
|
||||
Snake.__superClass__ = Animal.prototype;
|
||||
Snake.prototype = new Animal();
|
||||
Snake.prototype.constructor = Snake;
|
||||
Snake.prototype.move = function() {
|
||||
alert("Slithering...");
|
||||
return Snake.__superClass__.move.call(this, 5);
|
||||
};
|
||||
var Horse = function(name) {
|
||||
this.name = name;
|
||||
return this.name;
|
||||
};
|
||||
Horse.__superClass__ = Animal.prototype;
|
||||
Horse.prototype = new Animal();
|
||||
Horse.prototype.constructor = Horse;
|
||||
Horse.prototype.move = function() {
|
||||
alert("Galloping...");
|
||||
return Horse.__superClass__.move.call(this, 45);
|
||||
};
|
||||
var sam = new Snake("Sammy the Python");
|
||||
var tom = new Horse("Tommy the Palomino");
|
||||
sam.move();
|
||||
tom.move();
|
||||
})();
|
||||
@@ -1,16 +1,18 @@
|
||||
(function(){
|
||||
if (day === "Tuesday") {
|
||||
eat_breakfast();
|
||||
} else if (day === "Wednesday") {
|
||||
if (day === "Mon") {
|
||||
go_to_work();
|
||||
} else if (day === "Tue") {
|
||||
go_to_the_park();
|
||||
} else if (day === "Saturday") {
|
||||
} else if (day === "Thu") {
|
||||
go_ice_fishing();
|
||||
} else if (day === "Fri" || day === "Sat") {
|
||||
if (day === bingo_day) {
|
||||
go_to_bingo();
|
||||
go_dancing();
|
||||
}
|
||||
} else if (day === "Sunday") {
|
||||
} else if (day === "Sun") {
|
||||
go_to_church();
|
||||
} else {
|
||||
go_to_work();
|
||||
}
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -7,4 +7,4 @@
|
||||
} finally {
|
||||
clean_up();
|
||||
}
|
||||
})();
|
||||
})();
|
||||
|
||||
@@ -1,9 +1,22 @@
|
||||
(function(){
|
||||
while (demand > supply) {
|
||||
sell();
|
||||
restock();
|
||||
var _a, lyrics, num;
|
||||
// Econ 101
|
||||
if (this.studying_economics) {
|
||||
while (supply > demand) {
|
||||
buy();
|
||||
}
|
||||
while (supply < demand) {
|
||||
sell();
|
||||
}
|
||||
}
|
||||
while (supply > demand) {
|
||||
buy();
|
||||
}
|
||||
})();
|
||||
// Nursery Rhyme
|
||||
num = 6;
|
||||
lyrics = (function() {
|
||||
_a = [];
|
||||
while (num -= 1) {
|
||||
_a.push(num + " little monkeys, jumping on the bed. \
|
||||
One fell out and bumped his head.");
|
||||
}
|
||||
return _a;
|
||||
}).call(this);
|
||||
})();
|
||||
|
||||
668
documentation/underscore.html
Normal file
668
documentation/underscore.html
Normal file
@@ -0,0 +1,668 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
|
||||
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
|
||||
<link rel="stylesheet" type="text/css" media="screen,projection,print" href="css/idle.css" />
|
||||
<title>Underscore.coffee</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<pre class="idle"><span class="line-numbers"> 1 </span>
|
||||
<span class="line-numbers"> 2 </span> <span class="Comment"><span class="Comment">#</span> Underscore.coffee</span>
|
||||
<span class="line-numbers"> 3 </span> <span class="Comment"><span class="Comment">#</span> (c) 2010 Jeremy Ashkenas, DocumentCloud Inc.</span>
|
||||
<span class="line-numbers"> 4 </span> <span class="Comment"><span class="Comment">#</span> Underscore is freely distributable under the terms of the MIT license.</span>
|
||||
<span class="line-numbers"> 5 </span> <span class="Comment"><span class="Comment">#</span> Portions of Underscore are inspired by or borrowed from Prototype.js,</span>
|
||||
<span class="line-numbers"> 6 </span> <span class="Comment"><span class="Comment">#</span> Oliver Steele's Functional, and John Resig's Micro-Templating.</span>
|
||||
<span class="line-numbers"> 7 </span> <span class="Comment"><span class="Comment">#</span> For all details and documentation:</span>
|
||||
<span class="line-numbers"> 8 </span> <span class="Comment"><span class="Comment">#</span> http://documentcloud.github.com/underscore/</span>
|
||||
<span class="line-numbers"> 9 </span>
|
||||
<span class="line-numbers"> 10 </span>
|
||||
<span class="line-numbers"> 11 </span> <span class="Comment"><span class="Comment">#</span> ------------------------- Baseline setup ---------------------------------</span>
|
||||
<span class="line-numbers"> 12 </span>
|
||||
<span class="line-numbers"> 13 </span> <span class="Comment"><span class="Comment">#</span> Establish the root object, "window" in the browser, or "global" on the server.</span>
|
||||
<span class="line-numbers"> 14 </span> <span class="FunctionName">root</span><span class="Keyword">:</span> <span class="Variable">this</span>
|
||||
<span class="line-numbers"> 15 </span>
|
||||
<span class="line-numbers"> 16 </span>
|
||||
<span class="line-numbers"> 17 </span> <span class="Comment"><span class="Comment">#</span> Save the previous value of the "_" variable.</span>
|
||||
<span class="line-numbers"> 18 </span> <span class="FunctionName">previousUnderscore</span><span class="Keyword">:</span> root._
|
||||
<span class="line-numbers"> 19 </span>
|
||||
<span class="line-numbers"> 20 </span>
|
||||
<span class="line-numbers"> 21 </span> <span class="Comment"><span class="Comment">#</span> Establish the object that gets thrown to break out of a loop iteration.</span>
|
||||
<span class="line-numbers"> 22 </span> <span class="FunctionName">breaker</span><span class="Keyword">:</span> <span class="Keyword">if</span> <span class="Keyword">typeof</span>(StopIteration) <span class="Keyword">is</span> <span class="String"><span class="String">'</span>undefined<span class="String">'</span></span> <span class="Keyword">then</span> <span class="String"><span class="String">'</span>__break__<span class="String">'</span></span> <span class="Keyword">else</span> StopIteration
|
||||
<span class="line-numbers"> 23 </span>
|
||||
<span class="line-numbers"> 24 </span>
|
||||
<span class="line-numbers"> 25 </span> <span class="Comment"><span class="Comment">#</span> Quick regexp-escaping function, because JS doesn't have RegExp.escape().</span>
|
||||
<span class="line-numbers"> 26 </span> <span class="FunctionName">escapeRegExp</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">string</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> string.replace(<span class="String"><span class="String">/</span>([.*+?^${}()|[<span class="UserDefinedConstant">\]</span><span class="UserDefinedConstant">\/</span><span class="UserDefinedConstant">\\</span>])<span class="String">/</span>g</span>, <span class="String"><span class="String">'</span><span class="UserDefinedConstant">\\</span>$1<span class="String">'</span></span>)
|
||||
<span class="line-numbers"> 27 </span>
|
||||
<span class="line-numbers"> 28 </span>
|
||||
<span class="line-numbers"> 29 </span> <span class="Comment"><span class="Comment">#</span> Save bytes in the minified (but not gzipped) version:</span>
|
||||
<span class="line-numbers"> 30 </span> <span class="FunctionName">ArrayProto</span><span class="Keyword">:</span> Array.prototype
|
||||
<span class="line-numbers"> 31 </span> <span class="FunctionName">ObjProto</span><span class="Keyword">:</span> Object.prototype
|
||||
<span class="line-numbers"> 32 </span>
|
||||
<span class="line-numbers"> 33 </span>
|
||||
<span class="line-numbers"> 34 </span> <span class="Comment"><span class="Comment">#</span>Create quick reference variables for speed access to core prototypes.</span>
|
||||
<span class="line-numbers"> 35 </span> <span class="FunctionName">slice</span><span class="Keyword">:</span> ArrayProto.slice
|
||||
<span class="line-numbers"> 36 </span> <span class="FunctionName">unshift</span><span class="Keyword">:</span> ArrayProto.unshift
|
||||
<span class="line-numbers"> 37 </span> <span class="FunctionName">toString</span><span class="Keyword">:</span> ObjProto.toString
|
||||
<span class="line-numbers"> 38 </span> <span class="FunctionName">hasOwnProperty</span><span class="Keyword">:</span> ObjProto.hasOwnProperty
|
||||
<span class="line-numbers"> 39 </span> <span class="FunctionName">propertyIsEnumerable</span><span class="Keyword">:</span> ObjProto.propertyIsEnumerable
|
||||
<span class="line-numbers"> 40 </span>
|
||||
<span class="line-numbers"> 41 </span>
|
||||
<span class="line-numbers"> 42 </span> <span class="Comment"><span class="Comment">#</span> All ECMA5 native implementations we hope to use are declared here.</span>
|
||||
<span class="line-numbers"> 43 </span> <span class="FunctionName">nativeForEach</span><span class="Keyword">:</span> ArrayProto.forEach
|
||||
<span class="line-numbers"> 44 </span> <span class="FunctionName">nativeMap</span><span class="Keyword">:</span> ArrayProto.map
|
||||
<span class="line-numbers"> 45 </span> <span class="FunctionName">nativeReduce</span><span class="Keyword">:</span> ArrayProto.reduce
|
||||
<span class="line-numbers"> 46 </span> <span class="FunctionName">nativeReduceRight</span><span class="Keyword">:</span> ArrayProto.reduceRight
|
||||
<span class="line-numbers"> 47 </span> <span class="FunctionName">nativeFilter</span><span class="Keyword">:</span> ArrayProto.filter
|
||||
<span class="line-numbers"> 48 </span> <span class="FunctionName">nativeEvery</span><span class="Keyword">:</span> ArrayProto.every
|
||||
<span class="line-numbers"> 49 </span> <span class="FunctionName">nativeSome</span><span class="Keyword">:</span> ArrayProto.some
|
||||
<span class="line-numbers"> 50 </span> <span class="FunctionName">nativeIndexOf</span><span class="Keyword">:</span> ArrayProto.indexOf
|
||||
<span class="line-numbers"> 51 </span> <span class="FunctionName">nativeLastIndexOf</span><span class="Keyword">:</span> ArrayProto.lastIndexOf
|
||||
<span class="line-numbers"> 52 </span> <span class="FunctionName">nativeIsArray</span><span class="Keyword">:</span> Array.isArray
|
||||
<span class="line-numbers"> 53 </span> <span class="FunctionName">nativeKeys</span><span class="Keyword">:</span> Object.keys
|
||||
<span class="line-numbers"> 54 </span>
|
||||
<span class="line-numbers"> 55 </span>
|
||||
<span class="line-numbers"> 56 </span> <span class="Comment"><span class="Comment">#</span> Create a safe reference to the Underscore object for use below.</span>
|
||||
<span class="line-numbers"> 57 </span> <span class="FunctionName">_</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> <span class="Keyword">new</span> <span class="TypeName">wrapper</span>(obj)
|
||||
<span class="line-numbers"> 58 </span>
|
||||
<span class="line-numbers"> 59 </span>
|
||||
<span class="line-numbers"> 60 </span> <span class="Comment"><span class="Comment">#</span> Export the Underscore object for CommonJS.</span>
|
||||
<span class="line-numbers"> 61 </span> <span class="Keyword">if</span> <span class="Keyword">typeof</span>(exports) <span class="Keyword">!</span><span class="Keyword">=</span> <span class="String"><span class="String">'</span>undefined<span class="String">'</span></span> <span class="Keyword">then</span> <span class="FunctionName">exports._</span><span class="Keyword">:</span> _
|
||||
<span class="line-numbers"> 62 </span>
|
||||
<span class="line-numbers"> 63 </span>
|
||||
<span class="line-numbers"> 64 </span> <span class="Comment"><span class="Comment">#</span> Export Underscore to global scope.</span>
|
||||
<span class="line-numbers"> 65 </span> <span class="FunctionName">root._</span><span class="Keyword">:</span> _
|
||||
<span class="line-numbers"> 66 </span>
|
||||
<span class="line-numbers"> 67 </span>
|
||||
<span class="line-numbers"> 68 </span> <span class="Comment"><span class="Comment">#</span> Current version.</span>
|
||||
<span class="line-numbers"> 69 </span> <span class="FunctionName">_.VERSION</span><span class="Keyword">:</span> <span class="String"><span class="String">'</span>0.6.0<span class="String">'</span></span>
|
||||
<span class="line-numbers"> 70 </span>
|
||||
<span class="line-numbers"> 71 </span>
|
||||
<span class="line-numbers"> 72 </span> <span class="Comment"><span class="Comment">#</span> ------------------------ Collection Functions: ---------------------------</span>
|
||||
<span class="line-numbers"> 73 </span>
|
||||
<span class="line-numbers"> 74 </span> <span class="Comment"><span class="Comment">#</span> The cornerstone, an each implementation.</span>
|
||||
<span class="line-numbers"> 75 </span> <span class="Comment"><span class="Comment">#</span> Handles objects implementing forEach, arrays, and raw objects.</span>
|
||||
<span class="line-numbers"> 76 </span> <span class="FunctionName">_.each</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, iterator, context</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 77 </span> <span class="Keyword">try</span>
|
||||
<span class="line-numbers"> 78 </span> <span class="Keyword">if</span> nativeForEach <span class="Keyword">and</span> obj.forEach <span class="Keyword">is</span> nativeForEach
|
||||
<span class="line-numbers"> 79 </span> obj.forEach iterator, context
|
||||
<span class="line-numbers"> 80 </span> <span class="Keyword">else</span> <span class="Keyword">if</span> _.isNumber obj.length
|
||||
<span class="line-numbers"> 81 </span> iterator.call(context, obj[i], i, obj) <span class="Keyword">for</span> i <span class="Keyword">in</span> [<span class="Number">0</span>...obj.length]
|
||||
<span class="line-numbers"> 82 </span> <span class="Keyword">else</span>
|
||||
<span class="line-numbers"> 83 </span> iterator.call(context, val, key, obj) <span class="Keyword">for</span> key, val <span class="Keyword">of</span> obj
|
||||
<span class="line-numbers"> 84 </span> <span class="Keyword">catch</span> e
|
||||
<span class="line-numbers"> 85 </span> <span class="Keyword">throw</span> e <span class="Keyword">if</span> e <span class="Keyword">isnt</span> breaker
|
||||
<span class="line-numbers"> 86 </span> obj
|
||||
<span class="line-numbers"> 87 </span>
|
||||
<span class="line-numbers"> 88 </span>
|
||||
<span class="line-numbers"> 89 </span> <span class="Comment"><span class="Comment">#</span> Return the results of applying the iterator to each element. Use JavaScript</span>
|
||||
<span class="line-numbers"> 90 </span> <span class="Comment"><span class="Comment">#</span> 1.6's version of map, if possible.</span>
|
||||
<span class="line-numbers"> 91 </span> <span class="FunctionName">_.map</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, iterator, context</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 92 </span> <span class="Keyword">return</span> obj.map(iterator, context) <span class="Keyword">if</span> nativeMap <span class="Keyword">and</span> obj.map <span class="Keyword">is</span> nativeMap
|
||||
<span class="line-numbers"> 93 </span> <span class="FunctionName">results</span><span class="Keyword">:</span> []
|
||||
<span class="line-numbers"> 94 </span> _.each obj, <span class="FunctionArgument">(</span><span class="FunctionArgument">value, index, list</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 95 </span> results.push iterator.call context, value, index, list
|
||||
<span class="line-numbers"> 96 </span> results
|
||||
<span class="line-numbers"> 97 </span>
|
||||
<span class="line-numbers"> 98 </span>
|
||||
<span class="line-numbers"> 99 </span> <span class="Comment"><span class="Comment">#</span> Reduce builds up a single result from a list of values. Also known as</span>
|
||||
<span class="line-numbers"> 100 </span> <span class="Comment"><span class="Comment">#</span> inject, or foldl. Uses JavaScript 1.8's version of reduce, if possible.</span>
|
||||
<span class="line-numbers"> 101 </span> <span class="FunctionName">_.reduce</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, memo, iterator, context</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 102 </span> <span class="Keyword">return</span> obj.reduce(_.bind(iterator, context), memo) <span class="Keyword">if</span> nativeReduce <span class="Keyword">and</span> obj.reduce <span class="Keyword">is</span> nativeReduce
|
||||
<span class="line-numbers"> 103 </span> _.each obj, <span class="FunctionArgument">(</span><span class="FunctionArgument">value, index, list</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 104 </span> <span class="FunctionName">memo</span><span class="Keyword">:</span> iterator.call context, memo, value, index, list
|
||||
<span class="line-numbers"> 105 </span> memo
|
||||
<span class="line-numbers"> 106 </span>
|
||||
<span class="line-numbers"> 107 </span>
|
||||
<span class="line-numbers"> 108 </span> <span class="Comment"><span class="Comment">#</span> The right-associative version of reduce, also known as foldr. Uses</span>
|
||||
<span class="line-numbers"> 109 </span> <span class="Comment"><span class="Comment">#</span> JavaScript 1.8's version of reduceRight, if available.</span>
|
||||
<span class="line-numbers"> 110 </span> <span class="FunctionName">_.reduceRight</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, memo, iterator, context</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 111 </span> <span class="Keyword">return</span> obj.reduceRight(_.bind(iterator, context), memo) <span class="Keyword">if</span> nativeReduceRight <span class="Keyword">and</span> obj.reduceRight <span class="Keyword">is</span> nativeReduceRight
|
||||
<span class="line-numbers"> 112 </span> _.each _.clone(_.toArray(obj)).reverse(), <span class="FunctionArgument">(</span><span class="FunctionArgument">value, index</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 113 </span> <span class="FunctionName">memo</span><span class="Keyword">:</span> iterator.call context, memo, value, index, obj
|
||||
<span class="line-numbers"> 114 </span> memo
|
||||
<span class="line-numbers"> 115 </span>
|
||||
<span class="line-numbers"> 116 </span>
|
||||
<span class="line-numbers"> 117 </span> <span class="Comment"><span class="Comment">#</span> Return the first value which passes a truth test.</span>
|
||||
<span class="line-numbers"> 118 </span> <span class="FunctionName">_.detect</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, iterator, context</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 119 </span> <span class="FunctionName">result</span><span class="Keyword">:</span> <span class="BuiltInConstant">null</span>
|
||||
<span class="line-numbers"> 120 </span> _.each obj, <span class="FunctionArgument">(</span><span class="FunctionArgument">value, index, list</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 121 </span> <span class="Keyword">if</span> iterator.call context, value, index, list
|
||||
<span class="line-numbers"> 122 </span> <span class="FunctionName">result</span><span class="Keyword">:</span> value
|
||||
<span class="line-numbers"> 123 </span> _.breakLoop()
|
||||
<span class="line-numbers"> 124 </span> result
|
||||
<span class="line-numbers"> 125 </span>
|
||||
<span class="line-numbers"> 126 </span>
|
||||
<span class="line-numbers"> 127 </span> <span class="Comment"><span class="Comment">#</span> Return all the elements that pass a truth test. Use JavaScript 1.6's</span>
|
||||
<span class="line-numbers"> 128 </span> <span class="Comment"><span class="Comment">#</span> filter(), if it exists.</span>
|
||||
<span class="line-numbers"> 129 </span> <span class="FunctionName">_.filter</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, iterator, context</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 130 </span> <span class="Keyword">return</span> obj.filter iterator, context <span class="Keyword">if</span> nativeFilter <span class="Keyword">and</span> obj.filter <span class="Keyword">is</span> nativeFilter
|
||||
<span class="line-numbers"> 131 </span> <span class="FunctionName">results</span><span class="Keyword">:</span> []
|
||||
<span class="line-numbers"> 132 </span> _.each obj, <span class="FunctionArgument">(</span><span class="FunctionArgument">value, index, list</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 133 </span> results.push value <span class="Keyword">if</span> iterator.call context, value, index, list
|
||||
<span class="line-numbers"> 134 </span> results
|
||||
<span class="line-numbers"> 135 </span>
|
||||
<span class="line-numbers"> 136 </span>
|
||||
<span class="line-numbers"> 137 </span> <span class="Comment"><span class="Comment">#</span> Return all the elements for which a truth test fails.</span>
|
||||
<span class="line-numbers"> 138 </span> <span class="FunctionName">_.reject</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, iterator, context</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 139 </span> <span class="FunctionName">results</span><span class="Keyword">:</span> []
|
||||
<span class="line-numbers"> 140 </span> _.each obj, <span class="FunctionArgument">(</span><span class="FunctionArgument">value, index, list</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 141 </span> results.push value <span class="Keyword">if</span> <span class="Keyword">not</span> iterator.call context, value, index, list
|
||||
<span class="line-numbers"> 142 </span> results
|
||||
<span class="line-numbers"> 143 </span>
|
||||
<span class="line-numbers"> 144 </span>
|
||||
<span class="line-numbers"> 145 </span> <span class="Comment"><span class="Comment">#</span> Determine whether all of the elements match a truth test. Delegate to</span>
|
||||
<span class="line-numbers"> 146 </span> <span class="Comment"><span class="Comment">#</span> JavaScript 1.6's every(), if it is present.</span>
|
||||
<span class="line-numbers"> 147 </span> <span class="FunctionName">_.every</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, iterator, context</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 148 </span> iterator <span class="Keyword">||</span><span class="Keyword">=</span> _.identity
|
||||
<span class="line-numbers"> 149 </span> <span class="Keyword">return</span> obj.every iterator, context <span class="Keyword">if</span> nativeEvery <span class="Keyword">and</span> obj.every <span class="Keyword">is</span> nativeEvery
|
||||
<span class="line-numbers"> 150 </span> <span class="FunctionName">result</span><span class="Keyword">:</span> <span class="BuiltInConstant">true</span>
|
||||
<span class="line-numbers"> 151 </span> _.each obj, <span class="FunctionArgument">(</span><span class="FunctionArgument">value, index, list</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 152 </span> _.breakLoop() <span class="Keyword">unless</span> (<span class="FunctionName">result</span><span class="Keyword">:</span> result <span class="Keyword">and</span> iterator.call(context, value, index, list))
|
||||
<span class="line-numbers"> 153 </span> result
|
||||
<span class="line-numbers"> 154 </span>
|
||||
<span class="line-numbers"> 155 </span>
|
||||
<span class="line-numbers"> 156 </span> <span class="Comment"><span class="Comment">#</span> Determine if at least one element in the object matches a truth test. Use</span>
|
||||
<span class="line-numbers"> 157 </span> <span class="Comment"><span class="Comment">#</span> JavaScript 1.6's some(), if it exists.</span>
|
||||
<span class="line-numbers"> 158 </span> <span class="FunctionName">_.some</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, iterator, context</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 159 </span> iterator <span class="Keyword">||</span><span class="Keyword">=</span> _.identity
|
||||
<span class="line-numbers"> 160 </span> <span class="Keyword">return</span> obj.some iterator, context <span class="Keyword">if</span> nativeSome <span class="Keyword">and</span> obj.some <span class="Keyword">is</span> nativeSome
|
||||
<span class="line-numbers"> 161 </span> <span class="FunctionName">result</span><span class="Keyword">:</span> <span class="BuiltInConstant">false</span>
|
||||
<span class="line-numbers"> 162 </span> _.each obj, <span class="FunctionArgument">(</span><span class="FunctionArgument">value, index, list</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 163 </span> _.breakLoop() <span class="Keyword">if</span> (<span class="FunctionName">result</span><span class="Keyword">:</span> iterator.call(context, value, index, list))
|
||||
<span class="line-numbers"> 164 </span> result
|
||||
<span class="line-numbers"> 165 </span>
|
||||
<span class="line-numbers"> 166 </span>
|
||||
<span class="line-numbers"> 167 </span> <span class="Comment"><span class="Comment">#</span> Determine if a given value is included in the array or object,</span>
|
||||
<span class="line-numbers"> 168 </span> <span class="Comment"><span class="Comment">#</span> based on '==='.</span>
|
||||
<span class="line-numbers"> 169 </span> <span class="FunctionName">_.include</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, target</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 170 </span> <span class="Keyword">return</span> _.indexOf(obj, target) <span class="Keyword">isnt</span> <span class="Keyword">-</span><span class="Number">1</span> <span class="Keyword">if</span> nativeIndexOf <span class="Keyword">and</span> obj.indexOf <span class="Keyword">is</span> nativeIndexOf
|
||||
<span class="line-numbers"> 171 </span> <span class="Keyword">for</span> key, val <span class="Keyword">of</span> obj
|
||||
<span class="line-numbers"> 172 </span> <span class="Keyword">return</span> <span class="BuiltInConstant">true</span> <span class="Keyword">if</span> val <span class="Keyword">is</span> target
|
||||
<span class="line-numbers"> 173 </span> <span class="BuiltInConstant">false</span>
|
||||
<span class="line-numbers"> 174 </span>
|
||||
<span class="line-numbers"> 175 </span>
|
||||
<span class="line-numbers"> 176 </span> <span class="Comment"><span class="Comment">#</span> Invoke a method with arguments on every item in a collection.</span>
|
||||
<span class="line-numbers"> 177 </span> <span class="FunctionName">_.invoke</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, method</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 178 </span> <span class="FunctionName">args</span><span class="Keyword">:</span> _.rest arguments, <span class="Number">2</span>
|
||||
<span class="line-numbers"> 179 </span> (<span class="Keyword">if</span> method <span class="Keyword">then</span> val[method] <span class="Keyword">else</span> val).apply(val, args) <span class="Keyword">for</span> val <span class="Keyword">in</span> obj
|
||||
<span class="line-numbers"> 180 </span>
|
||||
<span class="line-numbers"> 181 </span>
|
||||
<span class="line-numbers"> 182 </span> <span class="Comment"><span class="Comment">#</span> Convenience version of a common use case of map: fetching a property.</span>
|
||||
<span class="line-numbers"> 183 </span> <span class="FunctionName">_.pluck</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, key</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 184 </span> _.map(obj, <span class="FunctionArgument">(</span><span class="FunctionArgument">val</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> val[key])
|
||||
<span class="line-numbers"> 185 </span>
|
||||
<span class="line-numbers"> 186 </span>
|
||||
<span class="line-numbers"> 187 </span> <span class="Comment"><span class="Comment">#</span> Return the maximum item or (item-based computation).</span>
|
||||
<span class="line-numbers"> 188 </span> <span class="FunctionName">_.max</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, iterator, context</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 189 </span> <span class="Keyword">return</span> Math.max.apply(Math, obj) <span class="Keyword">if</span> <span class="Keyword">not</span> iterator <span class="Keyword">and</span> _.isArray(obj)
|
||||
<span class="line-numbers"> 190 </span> <span class="FunctionName">result</span><span class="Keyword">:</span> {<span class="FunctionName">computed</span><span class="Keyword">:</span> <span class="Keyword">-</span><span class="BuiltInConstant">Infinity</span>}
|
||||
<span class="line-numbers"> 191 </span> _.each obj, <span class="FunctionArgument">(</span><span class="FunctionArgument">value, index, list</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 192 </span> <span class="FunctionName">computed</span><span class="Keyword">:</span> <span class="Keyword">if</span> iterator <span class="Keyword">then</span> iterator.call(context, value, index, list) <span class="Keyword">else</span> value
|
||||
<span class="line-numbers"> 193 </span> computed <span class="Keyword">>=</span> result.computed <span class="Keyword">and</span> (<span class="FunctionName">result</span><span class="Keyword">:</span> {<span class="FunctionName">value</span><span class="Keyword">:</span> value, <span class="FunctionName">computed</span><span class="Keyword">:</span> computed})
|
||||
<span class="line-numbers"> 194 </span> result.value
|
||||
<span class="line-numbers"> 195 </span>
|
||||
<span class="line-numbers"> 196 </span>
|
||||
<span class="line-numbers"> 197 </span> <span class="Comment"><span class="Comment">#</span> Return the minimum element (or element-based computation).</span>
|
||||
<span class="line-numbers"> 198 </span> <span class="FunctionName">_.min</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, iterator, context</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 199 </span> <span class="Keyword">return</span> Math.min.apply(Math, obj) <span class="Keyword">if</span> <span class="Keyword">not</span> iterator <span class="Keyword">and</span> _.isArray(obj)
|
||||
<span class="line-numbers"> 200 </span> <span class="FunctionName">result</span><span class="Keyword">:</span> {<span class="FunctionName">computed</span><span class="Keyword">:</span> <span class="BuiltInConstant">Infinity</span>}
|
||||
<span class="line-numbers"> 201 </span> _.each obj, <span class="FunctionArgument">(</span><span class="FunctionArgument">value, index, list</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 202 </span> <span class="FunctionName">computed</span><span class="Keyword">:</span> <span class="Keyword">if</span> iterator <span class="Keyword">then</span> iterator.call(context, value, index, list) <span class="Keyword">else</span> value
|
||||
<span class="line-numbers"> 203 </span> computed <span class="Keyword"><</span> result.computed <span class="Keyword">and</span> (<span class="FunctionName">result</span><span class="Keyword">:</span> {<span class="FunctionName">value</span><span class="Keyword">:</span> value, <span class="FunctionName">computed</span><span class="Keyword">:</span> computed})
|
||||
<span class="line-numbers"> 204 </span> result.value
|
||||
<span class="line-numbers"> 205 </span>
|
||||
<span class="line-numbers"> 206 </span>
|
||||
<span class="line-numbers"> 207 </span> <span class="Comment"><span class="Comment">#</span> Sort the object's values by a criterion produced by an iterator.</span>
|
||||
<span class="line-numbers"> 208 </span> <span class="FunctionName">_.sortBy</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, iterator, context</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 209 </span> _.pluck(((_.map obj, <span class="FunctionArgument">(</span><span class="FunctionArgument">value, index, list</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 210 </span> {<span class="FunctionName">value</span><span class="Keyword">:</span> value, <span class="FunctionName">criteria</span><span class="Keyword">:</span> iterator.call(context, value, index, list)}
|
||||
<span class="line-numbers"> 211 </span> ).sort(<span class="FunctionArgument">(</span><span class="FunctionArgument">left, right</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 212 </span> <span class="FunctionName">a</span><span class="Keyword">:</span> left.criteria; <span class="FunctionName">b</span><span class="Keyword">:</span> right.criteria
|
||||
<span class="line-numbers"> 213 </span> <span class="Keyword">if</span> a <span class="Keyword"><</span> b <span class="Keyword">then</span> <span class="Keyword">-</span><span class="Number">1</span> <span class="Keyword">else</span> <span class="Keyword">if</span> a <span class="Keyword">></span> b <span class="Keyword">then</span> <span class="Number">1</span> <span class="Keyword">else</span> <span class="Number">0</span>
|
||||
<span class="line-numbers"> 214 </span> )), <span class="String"><span class="String">'</span>value<span class="String">'</span></span>)
|
||||
<span class="line-numbers"> 215 </span>
|
||||
<span class="line-numbers"> 216 </span>
|
||||
<span class="line-numbers"> 217 </span> <span class="Comment"><span class="Comment">#</span> Use a comparator function to figure out at what index an object should</span>
|
||||
<span class="line-numbers"> 218 </span> <span class="Comment"><span class="Comment">#</span> be inserted so as to maintain order. Uses binary search.</span>
|
||||
<span class="line-numbers"> 219 </span> <span class="FunctionName">_.sortedIndex</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">array, obj, iterator</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 220 </span> iterator <span class="Keyword">||</span><span class="Keyword">=</span> _.identity
|
||||
<span class="line-numbers"> 221 </span> <span class="FunctionName">low</span><span class="Keyword">:</span> <span class="Number">0</span>
|
||||
<span class="line-numbers"> 222 </span> <span class="FunctionName">high</span><span class="Keyword">:</span> array.length
|
||||
<span class="line-numbers"> 223 </span> <span class="Keyword">while</span> low <span class="Keyword"><</span> high
|
||||
<span class="line-numbers"> 224 </span> <span class="FunctionName">mid</span><span class="Keyword">:</span> (low <span class="Keyword">+</span> high) <span class="Keyword">></span><span class="Keyword">></span> <span class="Number">1</span>
|
||||
<span class="line-numbers"> 225 </span> <span class="Keyword">if</span> iterator(array[mid]) <span class="Keyword"><</span> iterator(obj) <span class="Keyword">then</span> <span class="FunctionName">low</span><span class="Keyword">:</span> mid <span class="Keyword">+</span> <span class="Number">1</span> <span class="Keyword">else</span> <span class="FunctionName">high</span><span class="Keyword">:</span> mid
|
||||
<span class="line-numbers"> 226 </span> low
|
||||
<span class="line-numbers"> 227 </span>
|
||||
<span class="line-numbers"> 228 </span>
|
||||
<span class="line-numbers"> 229 </span> <span class="Comment"><span class="Comment">#</span> Convert anything iterable into a real, live array.</span>
|
||||
<span class="line-numbers"> 230 </span> <span class="FunctionName">_.toArray</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">iterable</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 231 </span> <span class="Keyword">return</span> [] <span class="Keyword">if</span> (<span class="Keyword">!</span>iterable)
|
||||
<span class="line-numbers"> 232 </span> <span class="Keyword">return</span> iterable.toArray() <span class="Keyword">if</span> (iterable.toArray)
|
||||
<span class="line-numbers"> 233 </span> <span class="Keyword">return</span> iterable <span class="Keyword">if</span> (_.isArray(iterable))
|
||||
<span class="line-numbers"> 234 </span> <span class="Keyword">return</span> slice.call(iterable) <span class="Keyword">if</span> (_.isArguments(iterable))
|
||||
<span class="line-numbers"> 235 </span> _.values(iterable)
|
||||
<span class="line-numbers"> 236 </span>
|
||||
<span class="line-numbers"> 237 </span>
|
||||
<span class="line-numbers"> 238 </span> <span class="Comment"><span class="Comment">#</span> Return the number of elements in an object.</span>
|
||||
<span class="line-numbers"> 239 </span> <span class="FunctionName">_.size</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> _.toArray(obj).length
|
||||
<span class="line-numbers"> 240 </span>
|
||||
<span class="line-numbers"> 241 </span>
|
||||
<span class="line-numbers"> 242 </span> <span class="Comment"><span class="Comment">#</span> -------------------------- Array Functions: ------------------------------</span>
|
||||
<span class="line-numbers"> 243 </span>
|
||||
<span class="line-numbers"> 244 </span> <span class="Comment"><span class="Comment">#</span> Get the first element of an array. Passing "n" will return the first N</span>
|
||||
<span class="line-numbers"> 245 </span> <span class="Comment"><span class="Comment">#</span> values in the array. Aliased as "head". The "guard" check allows it to work</span>
|
||||
<span class="line-numbers"> 246 </span> <span class="Comment"><span class="Comment">#</span> with _.map.</span>
|
||||
<span class="line-numbers"> 247 </span> <span class="FunctionName">_.first</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">array, n, guard</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 248 </span> <span class="Keyword">if</span> n <span class="Keyword">and</span> <span class="Keyword">not</span> guard <span class="Keyword">then</span> slice.call(array, <span class="Number">0</span>, n) <span class="Keyword">else</span> array[<span class="Number">0</span>]
|
||||
<span class="line-numbers"> 249 </span>
|
||||
<span class="line-numbers"> 250 </span>
|
||||
<span class="line-numbers"> 251 </span> <span class="Comment"><span class="Comment">#</span> Returns everything but the first entry of the array. Aliased as "tail".</span>
|
||||
<span class="line-numbers"> 252 </span> <span class="Comment"><span class="Comment">#</span> Especially useful on the arguments object. Passing an "index" will return</span>
|
||||
<span class="line-numbers"> 253 </span> <span class="Comment"><span class="Comment">#</span> the rest of the values in the array from that index onward. The "guard"</span>
|
||||
<span class="line-numbers"> 254 </span> <span class="Comment"><span class="Comment">#</span> check allows it to work with _.map.</span>
|
||||
<span class="line-numbers"> 255 </span> <span class="FunctionName">_.rest</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">array, index, guard</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 256 </span> slice.call(array, <span class="Keyword">if</span> _.isUndefined(index) <span class="Keyword">or</span> guard <span class="Keyword">then</span> <span class="Number">1</span> <span class="Keyword">else</span> index)
|
||||
<span class="line-numbers"> 257 </span>
|
||||
<span class="line-numbers"> 258 </span>
|
||||
<span class="line-numbers"> 259 </span> <span class="Comment"><span class="Comment">#</span> Get the last element of an array.</span>
|
||||
<span class="line-numbers"> 260 </span> <span class="FunctionName">_.last</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">array</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> array[array.length <span class="Keyword">-</span> <span class="Number">1</span>]
|
||||
<span class="line-numbers"> 261 </span>
|
||||
<span class="line-numbers"> 262 </span>
|
||||
<span class="line-numbers"> 263 </span> <span class="Comment"><span class="Comment">#</span> Trim out all falsy values from an array.</span>
|
||||
<span class="line-numbers"> 264 </span> <span class="FunctionName">_.compact</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">array</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> item <span class="Keyword">for</span> item <span class="Keyword">in</span> array <span class="Keyword">when</span> item
|
||||
<span class="line-numbers"> 265 </span>
|
||||
<span class="line-numbers"> 266 </span>
|
||||
<span class="line-numbers"> 267 </span> <span class="Comment"><span class="Comment">#</span> Return a completely flattened version of an array.</span>
|
||||
<span class="line-numbers"> 268 </span> <span class="FunctionName">_.flatten</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">array</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 269 </span> _.reduce array, [], <span class="FunctionArgument">(</span><span class="FunctionArgument">memo, value</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 270 </span> <span class="Keyword">return</span> memo.concat(_.flatten(value)) <span class="Keyword">if</span> _.isArray value
|
||||
<span class="line-numbers"> 271 </span> memo.push value
|
||||
<span class="line-numbers"> 272 </span> memo
|
||||
<span class="line-numbers"> 273 </span>
|
||||
<span class="line-numbers"> 274 </span>
|
||||
<span class="line-numbers"> 275 </span> <span class="Comment"><span class="Comment">#</span> Return a version of the array that does not contain the specified value(s).</span>
|
||||
<span class="line-numbers"> 276 </span> <span class="FunctionName">_.without</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">array</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 277 </span> <span class="FunctionName">values</span><span class="Keyword">:</span> _.rest arguments
|
||||
<span class="line-numbers"> 278 </span> val <span class="Keyword">for</span> val <span class="Keyword">in</span> _.toArray(array) <span class="Keyword">when</span> <span class="Keyword">not</span> _.include values, val
|
||||
<span class="line-numbers"> 279 </span>
|
||||
<span class="line-numbers"> 280 </span>
|
||||
<span class="line-numbers"> 281 </span> <span class="Comment"><span class="Comment">#</span> Produce a duplicate-free version of the array. If the array has already</span>
|
||||
<span class="line-numbers"> 282 </span> <span class="Comment"><span class="Comment">#</span> been sorted, you have the option of using a faster algorithm.</span>
|
||||
<span class="line-numbers"> 283 </span> <span class="FunctionName">_.uniq</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">array, isSorted</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 284 </span> <span class="FunctionName">memo</span><span class="Keyword">:</span> []
|
||||
<span class="line-numbers"> 285 </span> <span class="Keyword">for</span> el, i <span class="Keyword">in</span> _.toArray array
|
||||
<span class="line-numbers"> 286 </span> memo.push el <span class="Keyword">if</span> i <span class="Keyword">is</span> <span class="Number">0</span> <span class="Keyword">||</span> (<span class="Keyword">if</span> isSorted <span class="Keyword">is</span> <span class="BuiltInConstant">true</span> <span class="Keyword">then</span> _.last(memo) <span class="Keyword">isnt</span> el <span class="Keyword">else</span> <span class="Keyword">not</span> _.include(memo, el))
|
||||
<span class="line-numbers"> 287 </span> memo
|
||||
<span class="line-numbers"> 288 </span>
|
||||
<span class="line-numbers"> 289 </span>
|
||||
<span class="line-numbers"> 290 </span> <span class="Comment"><span class="Comment">#</span> Produce an array that contains every item shared between all the</span>
|
||||
<span class="line-numbers"> 291 </span> <span class="Comment"><span class="Comment">#</span> passed-in arrays.</span>
|
||||
<span class="line-numbers"> 292 </span> <span class="FunctionName">_.intersect</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">array</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 293 </span> <span class="FunctionName">rest</span><span class="Keyword">:</span> _.rest arguments
|
||||
<span class="line-numbers"> 294 </span> _.select _.uniq(array), <span class="FunctionArgument">(</span><span class="FunctionArgument">item</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 295 </span> _.all rest, <span class="FunctionArgument">(</span><span class="FunctionArgument">other</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 296 </span> _.indexOf(other, item) <span class="Keyword">>=</span> <span class="Number">0</span>
|
||||
<span class="line-numbers"> 297 </span>
|
||||
<span class="line-numbers"> 298 </span>
|
||||
<span class="line-numbers"> 299 </span> <span class="Comment"><span class="Comment">#</span> Zip together multiple lists into a single array -- elements that share</span>
|
||||
<span class="line-numbers"> 300 </span> <span class="Comment"><span class="Comment">#</span> an index go together.</span>
|
||||
<span class="line-numbers"> 301 </span> <span class="FunctionName">_.zip</span><span class="Keyword">:</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 302 </span> <span class="FunctionName">length</span><span class="Keyword">:</span> _.max _.pluck arguments, <span class="String"><span class="String">'</span>length<span class="String">'</span></span>
|
||||
<span class="line-numbers"> 303 </span> <span class="FunctionName">results</span><span class="Keyword">:</span> <span class="Keyword">new</span> <span class="TypeName">Array</span> length
|
||||
<span class="line-numbers"> 304 </span> <span class="Keyword">for</span> i <span class="Keyword">in</span> [<span class="Number">0</span>...length]
|
||||
<span class="line-numbers"> 305 </span> results[i]<span class="Keyword">:</span> _.pluck arguments, String i
|
||||
<span class="line-numbers"> 306 </span> results
|
||||
<span class="line-numbers"> 307 </span>
|
||||
<span class="line-numbers"> 308 </span>
|
||||
<span class="line-numbers"> 309 </span> <span class="Comment"><span class="Comment">#</span> If the browser doesn't supply us with indexOf (I'm looking at you, MSIE),</span>
|
||||
<span class="line-numbers"> 310 </span> <span class="Comment"><span class="Comment">#</span> we need this function. Return the position of the first occurence of an</span>
|
||||
<span class="line-numbers"> 311 </span> <span class="Comment"><span class="Comment">#</span> item in an array, or -1 if the item is not included in the array.</span>
|
||||
<span class="line-numbers"> 312 </span> <span class="FunctionName">_.indexOf</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">array, item</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 313 </span> <span class="Keyword">return</span> array.indexOf item <span class="Keyword">if</span> nativeIndexOf <span class="Keyword">and</span> array.indexOf <span class="Keyword">is</span> nativeIndexOf
|
||||
<span class="line-numbers"> 314 </span> <span class="FunctionName">i</span><span class="Keyword">:</span> <span class="Number">0</span>; <span class="FunctionName">l</span><span class="Keyword">:</span> array.length
|
||||
<span class="line-numbers"> 315 </span> <span class="Keyword">while</span> l <span class="Keyword">-</span> i
|
||||
<span class="line-numbers"> 316 </span> <span class="Keyword">if</span> array[i] <span class="Keyword">is</span> item <span class="Keyword">then</span> <span class="Keyword">return</span> i <span class="Keyword">else</span> i<span class="Keyword">++</span>
|
||||
<span class="line-numbers"> 317 </span> <span class="Keyword">-</span><span class="Number">1</span>
|
||||
<span class="line-numbers"> 318 </span>
|
||||
<span class="line-numbers"> 319 </span>
|
||||
<span class="line-numbers"> 320 </span> <span class="Comment"><span class="Comment">#</span> Provide JavaScript 1.6's lastIndexOf, delegating to the native function,</span>
|
||||
<span class="line-numbers"> 321 </span> <span class="Comment"><span class="Comment">#</span> if possible.</span>
|
||||
<span class="line-numbers"> 322 </span> <span class="FunctionName">_.lastIndexOf</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">array, item</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 323 </span> <span class="Keyword">return</span> array.lastIndexOf(item) <span class="Keyword">if</span> nativeLastIndexOf <span class="Keyword">and</span> array.lastIndexOf <span class="Keyword">is</span> nativeLastIndexOf
|
||||
<span class="line-numbers"> 324 </span> <span class="FunctionName">i</span><span class="Keyword">:</span> array.length
|
||||
<span class="line-numbers"> 325 </span> <span class="Keyword">while</span> i
|
||||
<span class="line-numbers"> 326 </span> <span class="Keyword">if</span> array[i] <span class="Keyword">is</span> item <span class="Keyword">then</span> <span class="Keyword">return</span> i <span class="Keyword">else</span> i<span class="Keyword">--</span>
|
||||
<span class="line-numbers"> 327 </span> <span class="Keyword">-</span><span class="Number">1</span>
|
||||
<span class="line-numbers"> 328 </span>
|
||||
<span class="line-numbers"> 329 </span>
|
||||
<span class="line-numbers"> 330 </span> <span class="Comment"><span class="Comment">#</span> Generate an integer Array containing an arithmetic progression. A port of</span>
|
||||
<span class="line-numbers"> 331 </span> <span class="Comment"><span class="Comment">#</span> the native Python range() function. See:</span>
|
||||
<span class="line-numbers"> 332 </span> <span class="Comment"><span class="Comment">#</span> http://docs.python.org/library/functions.html#range</span>
|
||||
<span class="line-numbers"> 333 </span> <span class="FunctionName">_.range</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">start, stop, step</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 334 </span> <span class="FunctionName">a</span><span class="Keyword">:</span> arguments
|
||||
<span class="line-numbers"> 335 </span> <span class="FunctionName">solo</span><span class="Keyword">:</span> a.length <span class="Keyword"><=</span> <span class="Number">1</span>
|
||||
<span class="line-numbers"> 336 </span> <span class="FunctionName">i</span><span class="Keyword">:</span> <span class="FunctionName">start</span><span class="Keyword">:</span> <span class="Keyword">if</span> solo <span class="Keyword">then</span> <span class="Number">0</span> <span class="Keyword">else</span> a[<span class="Number">0</span>]
|
||||
<span class="line-numbers"> 337 </span> <span class="FunctionName">stop</span><span class="Keyword">:</span> <span class="Keyword">if</span> solo <span class="Keyword">then</span> a[<span class="Number">0</span>] <span class="Keyword">else</span> a[<span class="Number">1</span>]
|
||||
<span class="line-numbers"> 338 </span> <span class="FunctionName">step</span><span class="Keyword">:</span> a[<span class="Number">2</span>] <span class="Keyword">or</span> <span class="Number">1</span>
|
||||
<span class="line-numbers"> 339 </span> <span class="FunctionName">len</span><span class="Keyword">:</span> Math.ceil((stop <span class="Keyword">-</span> start) <span class="Keyword">/</span> step)
|
||||
<span class="line-numbers"> 340 </span> <span class="Keyword">return</span> [] <span class="Keyword">if</span> len <span class="Keyword"><=</span> <span class="Number">0</span>
|
||||
<span class="line-numbers"> 341 </span> <span class="FunctionName">range</span><span class="Keyword">:</span> <span class="Keyword">new</span> <span class="TypeName">Array</span> len
|
||||
<span class="line-numbers"> 342 </span> <span class="FunctionName">idx</span><span class="Keyword">:</span> <span class="Number">0</span>
|
||||
<span class="line-numbers"> 343 </span> <span class="Keyword">while</span> <span class="BuiltInConstant">true</span>
|
||||
<span class="line-numbers"> 344 </span> <span class="Keyword">return</span> range <span class="Keyword">if</span> (<span class="Keyword">if</span> step <span class="Keyword">></span> <span class="Number">0</span> <span class="Keyword">then</span> i <span class="Keyword">-</span> stop <span class="Keyword">else</span> stop <span class="Keyword">-</span> i) <span class="Keyword">>=</span> <span class="Number">0</span>
|
||||
<span class="line-numbers"> 345 </span> range[idx]<span class="Keyword">:</span> i
|
||||
<span class="line-numbers"> 346 </span> idx<span class="Keyword">++</span>
|
||||
<span class="line-numbers"> 347 </span> i<span class="Keyword">+</span><span class="Keyword">=</span> step
|
||||
<span class="line-numbers"> 348 </span>
|
||||
<span class="line-numbers"> 349 </span>
|
||||
<span class="line-numbers"> 350 </span> <span class="Comment"><span class="Comment">#</span> ----------------------- Function Functions: -----------------------------</span>
|
||||
<span class="line-numbers"> 351 </span>
|
||||
<span class="line-numbers"> 352 </span> <span class="Comment"><span class="Comment">#</span> Create a function bound to a given object (assigning 'this', and arguments,</span>
|
||||
<span class="line-numbers"> 353 </span> <span class="Comment"><span class="Comment">#</span> optionally). Binding with arguments is also known as 'curry'.</span>
|
||||
<span class="line-numbers"> 354 </span> <span class="FunctionName">_.bind</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">func, obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 355 </span> <span class="FunctionName">args</span><span class="Keyword">:</span> _.rest arguments, <span class="Number">2</span>
|
||||
<span class="line-numbers"> 356 </span> <span class="Storage">-></span> func.apply obj <span class="Keyword">or</span> root, args.concat arguments
|
||||
<span class="line-numbers"> 357 </span>
|
||||
<span class="line-numbers"> 358 </span>
|
||||
<span class="line-numbers"> 359 </span> <span class="Comment"><span class="Comment">#</span> Bind all of an object's methods to that object. Useful for ensuring that</span>
|
||||
<span class="line-numbers"> 360 </span> <span class="Comment"><span class="Comment">#</span> all callbacks defined on an object belong to it.</span>
|
||||
<span class="line-numbers"> 361 </span> <span class="FunctionName">_.bindAll</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 362 </span> <span class="FunctionName">funcs</span><span class="Keyword">:</span> <span class="Keyword">if</span> arguments.length <span class="Keyword">></span> <span class="Number">1</span> <span class="Keyword">then</span> _.rest(arguments) <span class="Keyword">else</span> _.functions(obj)
|
||||
<span class="line-numbers"> 363 </span> _.each funcs, <span class="FunctionArgument">(</span><span class="FunctionArgument">f</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> obj[f]<span class="Keyword">:</span> _.bind obj[f], obj
|
||||
<span class="line-numbers"> 364 </span> obj
|
||||
<span class="line-numbers"> 365 </span>
|
||||
<span class="line-numbers"> 366 </span>
|
||||
<span class="line-numbers"> 367 </span> <span class="Comment"><span class="Comment">#</span> Delays a function for the given number of milliseconds, and then calls</span>
|
||||
<span class="line-numbers"> 368 </span> <span class="Comment"><span class="Comment">#</span> it with the arguments supplied.</span>
|
||||
<span class="line-numbers"> 369 </span> <span class="FunctionName">_.delay</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">func, wait</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 370 </span> <span class="FunctionName">args</span><span class="Keyword">:</span> _.rest arguments, <span class="Number">2</span>
|
||||
<span class="line-numbers"> 371 </span> setTimeout((<span class="Storage">-></span> func.apply(func, args)), wait)
|
||||
<span class="line-numbers"> 372 </span>
|
||||
<span class="line-numbers"> 373 </span>
|
||||
<span class="line-numbers"> 374 </span> <span class="Comment"><span class="Comment">#</span> Defers a function, scheduling it to run after the current call stack has</span>
|
||||
<span class="line-numbers"> 375 </span> <span class="Comment"><span class="Comment">#</span> cleared.</span>
|
||||
<span class="line-numbers"> 376 </span> <span class="FunctionName">_.defer</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">func</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 377 </span> _.delay.apply _, [func, <span class="Number">1</span>].concat _.rest arguments
|
||||
<span class="line-numbers"> 378 </span>
|
||||
<span class="line-numbers"> 379 </span>
|
||||
<span class="line-numbers"> 380 </span> <span class="Comment"><span class="Comment">#</span> Returns the first function passed as an argument to the second,</span>
|
||||
<span class="line-numbers"> 381 </span> <span class="Comment"><span class="Comment">#</span> allowing you to adjust arguments, run code before and after, and</span>
|
||||
<span class="line-numbers"> 382 </span> <span class="Comment"><span class="Comment">#</span> conditionally execute the original function.</span>
|
||||
<span class="line-numbers"> 383 </span> <span class="FunctionName">_.wrap</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">func, wrapper</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 384 </span> <span class="Storage">-></span> wrapper.apply wrapper, [func].concat arguments
|
||||
<span class="line-numbers"> 385 </span>
|
||||
<span class="line-numbers"> 386 </span>
|
||||
<span class="line-numbers"> 387 </span> <span class="Comment"><span class="Comment">#</span> Returns a function that is the composition of a list of functions, each</span>
|
||||
<span class="line-numbers"> 388 </span> <span class="Comment"><span class="Comment">#</span> consuming the return value of the function that follows.</span>
|
||||
<span class="line-numbers"> 389 </span> <span class="FunctionName">_.compose</span><span class="Keyword">:</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 390 </span> <span class="FunctionName">funcs</span><span class="Keyword">:</span> arguments
|
||||
<span class="line-numbers"> 391 </span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 392 </span> <span class="FunctionName">args</span><span class="Keyword">:</span> arguments
|
||||
<span class="line-numbers"> 393 </span> <span class="Keyword">for</span> i <span class="Keyword">in</span> [(funcs.length <span class="Keyword">-</span> <span class="Number">1</span>)..<span class="Number">0</span>]
|
||||
<span class="line-numbers"> 394 </span> <span class="FunctionName">args</span><span class="Keyword">:</span> [funcs[i].apply(<span class="Variable">this</span>, args)]
|
||||
<span class="line-numbers"> 395 </span> args[<span class="Number">0</span>]
|
||||
<span class="line-numbers"> 396 </span>
|
||||
<span class="line-numbers"> 397 </span>
|
||||
<span class="line-numbers"> 398 </span> <span class="Comment"><span class="Comment">#</span> ------------------------- Object Functions: ----------------------------</span>
|
||||
<span class="line-numbers"> 399 </span>
|
||||
<span class="line-numbers"> 400 </span> <span class="Comment"><span class="Comment">#</span> Retrieve the names of an object's properties.</span>
|
||||
<span class="line-numbers"> 401 </span> <span class="FunctionName">_.keys</span><span class="Keyword">:</span> nativeKeys <span class="Keyword">or</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 402 </span> <span class="Keyword">return</span> _.range <span class="Number">0</span>, obj.length <span class="Keyword">if</span> _.isArray(obj)
|
||||
<span class="line-numbers"> 403 </span> key <span class="Keyword">for</span> key, val <span class="Keyword">of</span> obj
|
||||
<span class="line-numbers"> 404 </span>
|
||||
<span class="line-numbers"> 405 </span>
|
||||
<span class="line-numbers"> 406 </span> <span class="Comment"><span class="Comment">#</span> Retrieve the values of an object's properties.</span>
|
||||
<span class="line-numbers"> 407 </span> <span class="FunctionName">_.values</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 408 </span> _.map obj, _.identity
|
||||
<span class="line-numbers"> 409 </span>
|
||||
<span class="line-numbers"> 410 </span>
|
||||
<span class="line-numbers"> 411 </span> <span class="Comment"><span class="Comment">#</span> Return a sorted list of the function names available in Underscore.</span>
|
||||
<span class="line-numbers"> 412 </span> <span class="FunctionName">_.functions</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 413 </span> _.filter(_.keys(obj), <span class="FunctionArgument">(</span><span class="FunctionArgument">key</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> _.isFunction(obj[key])).sort()
|
||||
<span class="line-numbers"> 414 </span>
|
||||
<span class="line-numbers"> 415 </span>
|
||||
<span class="line-numbers"> 416 </span> <span class="Comment"><span class="Comment">#</span> Extend a given object with all of the properties in a source object.</span>
|
||||
<span class="line-numbers"> 417 </span> <span class="FunctionName">_.extend</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">destination, source</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 418 </span> (destination[key]<span class="Keyword">:</span> val) <span class="Keyword">for</span> key, val <span class="Keyword">of</span> source
|
||||
<span class="line-numbers"> 419 </span> destination
|
||||
<span class="line-numbers"> 420 </span>
|
||||
<span class="line-numbers"> 421 </span>
|
||||
<span class="line-numbers"> 422 </span> <span class="Comment"><span class="Comment">#</span> Create a (shallow-cloned) duplicate of an object.</span>
|
||||
<span class="line-numbers"> 423 </span> <span class="FunctionName">_.clone</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 424 </span> <span class="Keyword">return</span> obj.slice <span class="Number">0</span> <span class="Keyword">if</span> _.isArray obj
|
||||
<span class="line-numbers"> 425 </span> _.extend {}, obj
|
||||
<span class="line-numbers"> 426 </span>
|
||||
<span class="line-numbers"> 427 </span>
|
||||
<span class="line-numbers"> 428 </span> <span class="Comment"><span class="Comment">#</span> Invokes interceptor with the obj, and then returns obj.</span>
|
||||
<span class="line-numbers"> 429 </span> <span class="Comment"><span class="Comment">#</span> The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.</span>
|
||||
<span class="line-numbers"> 430 </span> <span class="FunctionName">_.tap</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, interceptor</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 431 </span> interceptor obj
|
||||
<span class="line-numbers"> 432 </span> obj
|
||||
<span class="line-numbers"> 433 </span>
|
||||
<span class="line-numbers"> 434 </span>
|
||||
<span class="line-numbers"> 435 </span> <span class="Comment"><span class="Comment">#</span> Perform a deep comparison to check if two objects are equal.</span>
|
||||
<span class="line-numbers"> 436 </span> <span class="FunctionName">_.isEqual</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">a, b</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 437 </span> <span class="Comment"><span class="Comment">#</span> Check object identity.</span>
|
||||
<span class="line-numbers"> 438 </span> <span class="Keyword">return</span> <span class="BuiltInConstant">true</span> <span class="Keyword">if</span> a <span class="Keyword">is</span> b
|
||||
<span class="line-numbers"> 439 </span> <span class="Comment"><span class="Comment">#</span> Different types?</span>
|
||||
<span class="line-numbers"> 440 </span> <span class="FunctionName">atype</span><span class="Keyword">:</span> <span class="Keyword">typeof</span>(a); <span class="FunctionName">btype</span><span class="Keyword">:</span> <span class="Keyword">typeof</span>(b)
|
||||
<span class="line-numbers"> 441 </span> <span class="Keyword">return</span> <span class="BuiltInConstant">false</span> <span class="Keyword">if</span> atype <span class="Keyword">isnt</span> btype
|
||||
<span class="line-numbers"> 442 </span> <span class="Comment"><span class="Comment">#</span> Basic equality test (watch out for coercions).</span>
|
||||
<span class="line-numbers"> 443 </span> <span class="Keyword">return</span> <span class="BuiltInConstant">true</span> <span class="Keyword">if</span> <span class="String"><span class="String">`</span>a == b<span class="String">`</span></span>
|
||||
<span class="line-numbers"> 444 </span> <span class="Comment"><span class="Comment">#</span> One is falsy and the other truthy.</span>
|
||||
<span class="line-numbers"> 445 </span> <span class="Keyword">return</span> <span class="BuiltInConstant">false</span> <span class="Keyword">if</span> (<span class="Keyword">!</span>a <span class="Keyword">and</span> b) <span class="Keyword">or</span> (a <span class="Keyword">and</span> <span class="Keyword">!</span>b)
|
||||
<span class="line-numbers"> 446 </span> <span class="Comment"><span class="Comment">#</span> One of them implements an isEqual()?</span>
|
||||
<span class="line-numbers"> 447 </span> <span class="Keyword">return</span> a.isEqual(b) <span class="Keyword">if</span> a.isEqual
|
||||
<span class="line-numbers"> 448 </span> <span class="Comment"><span class="Comment">#</span> Check dates' integer values.</span>
|
||||
<span class="line-numbers"> 449 </span> <span class="Keyword">return</span> a.getTime() <span class="Keyword">is</span> b.getTime() <span class="Keyword">if</span> _.isDate(a) <span class="Keyword">and</span> _.isDate(b)
|
||||
<span class="line-numbers"> 450 </span> <span class="Comment"><span class="Comment">#</span> Both are NaN?</span>
|
||||
<span class="line-numbers"> 451 </span> <span class="Keyword">return</span> <span class="BuiltInConstant">true</span> <span class="Keyword">if</span> _.isNaN(a) <span class="Keyword">and</span> _.isNaN(b)
|
||||
<span class="line-numbers"> 452 </span> <span class="Comment"><span class="Comment">#</span> Compare regular expressions.</span>
|
||||
<span class="line-numbers"> 453 </span> <span class="Keyword">if</span> _.isRegExp(a) <span class="Keyword">and</span> _.isRegExp(b)
|
||||
<span class="line-numbers"> 454 </span> <span class="Keyword">return</span> a.source <span class="Keyword">is</span> b.source <span class="Keyword">and</span>
|
||||
<span class="line-numbers"> 455 </span> a.global <span class="Keyword">is</span> b.global <span class="Keyword">and</span>
|
||||
<span class="line-numbers"> 456 </span> a.ignoreCase <span class="Keyword">is</span> b.ignoreCase <span class="Keyword">and</span>
|
||||
<span class="line-numbers"> 457 </span> a.multiline <span class="Keyword">is</span> b.multiline
|
||||
<span class="line-numbers"> 458 </span> <span class="Comment"><span class="Comment">#</span> If a is not an object by this point, we can't handle it.</span>
|
||||
<span class="line-numbers"> 459 </span> <span class="Keyword">return</span> <span class="BuiltInConstant">false</span> <span class="Keyword">if</span> atype <span class="Keyword">isnt</span> <span class="String"><span class="String">'</span>object<span class="String">'</span></span>
|
||||
<span class="line-numbers"> 460 </span> <span class="Comment"><span class="Comment">#</span> Check for different array lengths before comparing contents.</span>
|
||||
<span class="line-numbers"> 461 </span> <span class="Keyword">return</span> <span class="BuiltInConstant">false</span> <span class="Keyword">if</span> a.length <span class="Keyword">and</span> (a.length <span class="Keyword">isnt</span> b.length)
|
||||
<span class="line-numbers"> 462 </span> <span class="Comment"><span class="Comment">#</span> Nothing else worked, deep compare the contents.</span>
|
||||
<span class="line-numbers"> 463 </span> <span class="FunctionName">aKeys</span><span class="Keyword">:</span> _.keys(a); <span class="FunctionName">bKeys</span><span class="Keyword">:</span> _.keys(b)
|
||||
<span class="line-numbers"> 464 </span> <span class="Comment"><span class="Comment">#</span> Different object sizes?</span>
|
||||
<span class="line-numbers"> 465 </span> <span class="Keyword">return</span> <span class="BuiltInConstant">false</span> <span class="Keyword">if</span> aKeys.length <span class="Keyword">isnt</span> bKeys.length
|
||||
<span class="line-numbers"> 466 </span> <span class="Comment"><span class="Comment">#</span> Recursive comparison of contents.</span>
|
||||
<span class="line-numbers"> 467 </span> (<span class="Keyword">return</span> <span class="BuiltInConstant">false</span>) <span class="Keyword">for</span> key, val <span class="Keyword">of</span> a <span class="Keyword">when</span> <span class="Keyword">!</span>_.isEqual(val, b[key])
|
||||
<span class="line-numbers"> 468 </span> <span class="BuiltInConstant">true</span>
|
||||
<span class="line-numbers"> 469 </span>
|
||||
<span class="line-numbers"> 470 </span>
|
||||
<span class="line-numbers"> 471 </span> <span class="Comment"><span class="Comment">#</span> Is a given array or object empty?</span>
|
||||
<span class="line-numbers"> 472 </span> <span class="FunctionName">_.isEmpty</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 473 </span> <span class="Keyword">return</span> obj.length <span class="Keyword">is</span> <span class="Number">0</span> <span class="Keyword">if</span> _.isArray obj
|
||||
<span class="line-numbers"> 474 </span> (<span class="Keyword">return</span> <span class="BuiltInConstant">false</span>) <span class="Keyword">for</span> key <span class="Keyword">of</span> obj <span class="Keyword">when</span> hasOwnProperty.call(obj, key)
|
||||
<span class="line-numbers"> 475 </span> <span class="BuiltInConstant">true</span>
|
||||
<span class="line-numbers"> 476 </span>
|
||||
<span class="line-numbers"> 477 </span>
|
||||
<span class="line-numbers"> 478 </span> <span class="Comment"><span class="Comment">#</span> Is a given value a DOM element?</span>
|
||||
<span class="line-numbers"> 479 </span> <span class="FunctionName">_.isElement</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> obj <span class="Keyword">and</span> obj.nodeType <span class="Keyword">is</span> <span class="Number">1</span>
|
||||
<span class="line-numbers"> 480 </span>
|
||||
<span class="line-numbers"> 481 </span>
|
||||
<span class="line-numbers"> 482 </span> <span class="Comment"><span class="Comment">#</span> Is a given value an array?</span>
|
||||
<span class="line-numbers"> 483 </span> <span class="FunctionName">_.isArray</span><span class="Keyword">:</span> nativeIsArray <span class="Keyword">or</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> <span class="Keyword">!</span><span class="Keyword">!</span>(obj <span class="Keyword">and</span> obj.concat <span class="Keyword">and</span> obj.unshift)
|
||||
<span class="line-numbers"> 484 </span>
|
||||
<span class="line-numbers"> 485 </span>
|
||||
<span class="line-numbers"> 486 </span> <span class="Comment"><span class="Comment">#</span> Is a given variable an arguments object?</span>
|
||||
<span class="line-numbers"> 487 </span> <span class="FunctionName">_.isArguments</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> obj <span class="Keyword">and</span> _.isNumber(obj.length) <span class="Keyword">and</span> <span class="Keyword">not</span> obj.concat <span class="Keyword">and</span>
|
||||
<span class="line-numbers"> 488 </span> <span class="Keyword">not</span> obj.substr <span class="Keyword">and</span> <span class="Keyword">not</span> obj.apply <span class="Keyword">and</span> <span class="Keyword">not</span> propertyIsEnumerable.call(obj, <span class="String"><span class="String">'</span>length<span class="String">'</span></span>)
|
||||
<span class="line-numbers"> 489 </span>
|
||||
<span class="line-numbers"> 490 </span>
|
||||
<span class="line-numbers"> 491 </span> <span class="Comment"><span class="Comment">#</span> Is the given value a function?</span>
|
||||
<span class="line-numbers"> 492 </span> <span class="FunctionName">_.isFunction</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> <span class="Keyword">!</span><span class="Keyword">!</span>(obj <span class="Keyword">and</span> obj.constructor <span class="Keyword">and</span> obj.call <span class="Keyword">and</span> obj.apply)
|
||||
<span class="line-numbers"> 493 </span>
|
||||
<span class="line-numbers"> 494 </span>
|
||||
<span class="line-numbers"> 495 </span> <span class="Comment"><span class="Comment">#</span> Is the given value a string?</span>
|
||||
<span class="line-numbers"> 496 </span> <span class="FunctionName">_.isString</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> <span class="Keyword">!</span><span class="Keyword">!</span>(obj <span class="Keyword">is</span> <span class="String"><span class="String">'</span><span class="String">'</span></span> <span class="Keyword">or</span> (obj <span class="Keyword">and</span> obj.charCodeAt <span class="Keyword">and</span> obj.substr))
|
||||
<span class="line-numbers"> 497 </span>
|
||||
<span class="line-numbers"> 498 </span>
|
||||
<span class="line-numbers"> 499 </span> <span class="Comment"><span class="Comment">#</span> Is a given value a number?</span>
|
||||
<span class="line-numbers"> 500 </span> <span class="FunctionName">_.isNumber</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> (obj <span class="Keyword">is</span> <span class="Keyword">+</span>obj) <span class="Keyword">or</span> toString.call(obj) <span class="Keyword">is</span> <span class="String"><span class="String">'</span>[object Number]<span class="String">'</span></span>
|
||||
<span class="line-numbers"> 501 </span>
|
||||
<span class="line-numbers"> 502 </span>
|
||||
<span class="line-numbers"> 503 </span> <span class="Comment"><span class="Comment">#</span> Is a given value a boolean?</span>
|
||||
<span class="line-numbers"> 504 </span> <span class="FunctionName">_.isBoolean</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> obj <span class="Keyword">is</span> <span class="BuiltInConstant">true</span> <span class="Keyword">or</span> obj <span class="Keyword">is</span> <span class="BuiltInConstant">false</span>
|
||||
<span class="line-numbers"> 505 </span>
|
||||
<span class="line-numbers"> 506 </span>
|
||||
<span class="line-numbers"> 507 </span> <span class="Comment"><span class="Comment">#</span> Is a given value a Date?</span>
|
||||
<span class="line-numbers"> 508 </span> <span class="FunctionName">_.isDate</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> <span class="Keyword">!</span><span class="Keyword">!</span>(obj <span class="Keyword">and</span> obj.getTimezoneOffset <span class="Keyword">and</span> obj.setUTCFullYear)
|
||||
<span class="line-numbers"> 509 </span>
|
||||
<span class="line-numbers"> 510 </span>
|
||||
<span class="line-numbers"> 511 </span> <span class="Comment"><span class="Comment">#</span> Is the given value a regular expression?</span>
|
||||
<span class="line-numbers"> 512 </span> <span class="FunctionName">_.isRegExp</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> <span class="Keyword">!</span><span class="Keyword">!</span>(obj <span class="Keyword">and</span> obj.exec <span class="Keyword">and</span> (obj.ignoreCase <span class="Keyword">or</span> obj.ignoreCase <span class="Keyword">is</span> <span class="BuiltInConstant">false</span>))
|
||||
<span class="line-numbers"> 513 </span>
|
||||
<span class="line-numbers"> 514 </span>
|
||||
<span class="line-numbers"> 515 </span> <span class="Comment"><span class="Comment">#</span> Is the given value NaN -- this one is interesting. NaN != NaN, and</span>
|
||||
<span class="line-numbers"> 516 </span> <span class="Comment"><span class="Comment">#</span> isNaN(undefined) == true, so we make sure it's a number first.</span>
|
||||
<span class="line-numbers"> 517 </span> <span class="FunctionName">_.isNaN</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> _.isNumber(obj) <span class="Keyword">and</span> window.isNaN(obj)
|
||||
<span class="line-numbers"> 518 </span>
|
||||
<span class="line-numbers"> 519 </span>
|
||||
<span class="line-numbers"> 520 </span> <span class="Comment"><span class="Comment">#</span> Is a given value equal to null?</span>
|
||||
<span class="line-numbers"> 521 </span> <span class="FunctionName">_.isNull</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> obj <span class="Keyword">is</span> <span class="BuiltInConstant">null</span>
|
||||
<span class="line-numbers"> 522 </span>
|
||||
<span class="line-numbers"> 523 </span>
|
||||
<span class="line-numbers"> 524 </span> <span class="Comment"><span class="Comment">#</span> Is a given variable undefined?</span>
|
||||
<span class="line-numbers"> 525 </span> <span class="FunctionName">_.isUndefined</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> <span class="Keyword">typeof</span> obj <span class="Keyword">is</span> <span class="String"><span class="String">'</span>undefined<span class="String">'</span></span>
|
||||
<span class="line-numbers"> 526 </span>
|
||||
<span class="line-numbers"> 527 </span>
|
||||
<span class="line-numbers"> 528 </span> <span class="Comment"><span class="Comment">#</span> -------------------------- Utility Functions: --------------------------</span>
|
||||
<span class="line-numbers"> 529 </span>
|
||||
<span class="line-numbers"> 530 </span> <span class="Comment"><span class="Comment">#</span> Run Underscore.js in noConflict mode, returning the '_' variable to its</span>
|
||||
<span class="line-numbers"> 531 </span> <span class="Comment"><span class="Comment">#</span> previous owner. Returns a reference to the Underscore object.</span>
|
||||
<span class="line-numbers"> 532 </span> <span class="FunctionName">_.noConflict</span><span class="Keyword">:</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 533 </span> <span class="FunctionName">root._</span><span class="Keyword">:</span> previousUnderscore
|
||||
<span class="line-numbers"> 534 </span> <span class="Variable">this</span>
|
||||
<span class="line-numbers"> 535 </span>
|
||||
<span class="line-numbers"> 536 </span>
|
||||
<span class="line-numbers"> 537 </span> <span class="Comment"><span class="Comment">#</span> Keep the identity function around for default iterators.</span>
|
||||
<span class="line-numbers"> 538 </span> <span class="FunctionName">_.identity</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">value</span><span class="FunctionArgument">)</span> <span class="Storage">-></span> value
|
||||
<span class="line-numbers"> 539 </span>
|
||||
<span class="line-numbers"> 540 </span>
|
||||
<span class="line-numbers"> 541 </span> <span class="Comment"><span class="Comment">#</span> Run a function n times.</span>
|
||||
<span class="line-numbers"> 542 </span> <span class="FunctionName">_.times</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">n, iterator, context</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 543 </span> iterator.call(context, i) <span class="Keyword">for</span> i <span class="Keyword">in</span> [<span class="Number">0</span>...n]
|
||||
<span class="line-numbers"> 544 </span>
|
||||
<span class="line-numbers"> 545 </span>
|
||||
<span class="line-numbers"> 546 </span> <span class="Comment"><span class="Comment">#</span> Break out of the middle of an iteration.</span>
|
||||
<span class="line-numbers"> 547 </span> <span class="FunctionName">_.breakLoop</span><span class="Keyword">:</span> <span class="Storage">-></span> <span class="Keyword">throw</span> breaker
|
||||
<span class="line-numbers"> 548 </span>
|
||||
<span class="line-numbers"> 549 </span>
|
||||
<span class="line-numbers"> 550 </span> <span class="Comment"><span class="Comment">#</span> Add your own custom functions to the Underscore object, ensuring that</span>
|
||||
<span class="line-numbers"> 551 </span> <span class="Comment"><span class="Comment">#</span> they're correctly added to the OOP wrapper as well.</span>
|
||||
<span class="line-numbers"> 552 </span> <span class="FunctionName">_.mixin</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 553 </span> <span class="Keyword">for</span> name <span class="Keyword">in</span> _.functions(obj)
|
||||
<span class="line-numbers"> 554 </span> addToWrapper name, _[name]<span class="Keyword">:</span> obj[name]
|
||||
<span class="line-numbers"> 555 </span>
|
||||
<span class="line-numbers"> 556 </span>
|
||||
<span class="line-numbers"> 557 </span> <span class="Comment"><span class="Comment">#</span> Generate a unique integer id (unique within the entire client session).</span>
|
||||
<span class="line-numbers"> 558 </span> <span class="Comment"><span class="Comment">#</span> Useful for temporary DOM ids.</span>
|
||||
<span class="line-numbers"> 559 </span> <span class="FunctionName">idCounter</span><span class="Keyword">:</span> <span class="Number">0</span>
|
||||
<span class="line-numbers"> 560 </span> <span class="FunctionName">_.uniqueId</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">prefix</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 561 </span> (prefix <span class="Keyword">or</span> <span class="String"><span class="String">'</span><span class="String">'</span></span>) <span class="Keyword">+</span> idCounter<span class="Keyword">++</span>
|
||||
<span class="line-numbers"> 562 </span>
|
||||
<span class="line-numbers"> 563 </span>
|
||||
<span class="line-numbers"> 564 </span> <span class="Comment"><span class="Comment">#</span> By default, Underscore uses ERB-style template delimiters, change the</span>
|
||||
<span class="line-numbers"> 565 </span> <span class="Comment"><span class="Comment">#</span> following template settings to use alternative delimiters.</span>
|
||||
<span class="line-numbers"> 566 </span> <span class="FunctionName">_.templateSettings</span><span class="Keyword">:</span> {
|
||||
<span class="line-numbers"> 567 </span> <span class="FunctionName">start</span><span class="Keyword">:</span> <span class="String"><span class="String">'</span><%<span class="String">'</span></span>
|
||||
<span class="line-numbers"> 568 </span> <span class="FunctionName">end</span><span class="Keyword">:</span> <span class="String"><span class="String">'</span>%><span class="String">'</span></span>
|
||||
<span class="line-numbers"> 569 </span> <span class="FunctionName">interpolate</span><span class="Keyword">:</span><span class="String"> <span class="String">/</span><%=(.+?)%><span class="String">/</span>g</span>
|
||||
<span class="line-numbers"> 570 </span> }
|
||||
<span class="line-numbers"> 571 </span>
|
||||
<span class="line-numbers"> 572 </span>
|
||||
<span class="line-numbers"> 573 </span> <span class="Comment"><span class="Comment">#</span> JavaScript templating a-la ERB, pilfered from John Resig's</span>
|
||||
<span class="line-numbers"> 574 </span> <span class="Comment"><span class="Comment">#</span> "Secrets of the JavaScript Ninja", page 83.</span>
|
||||
<span class="line-numbers"> 575 </span> <span class="Comment"><span class="Comment">#</span> Single-quote fix from Rick Strahl's version.</span>
|
||||
<span class="line-numbers"> 576 </span> <span class="FunctionName">_.template</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">str, data</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 577 </span> <span class="FunctionName">c</span><span class="Keyword">:</span> _.templateSettings
|
||||
<span class="line-numbers"> 578 </span> <span class="FunctionName">endMatch</span><span class="Keyword">:</span> <span class="Keyword">new</span> <span class="TypeName">RegExp</span>(<span class="String"><span class="String">"</span>'(?=[^<span class="String">"</span></span><span class="Keyword">+</span>c.end.substr(<span class="Number">0</span>, <span class="Number">1</span>)<span class="Keyword">+</span><span class="String"><span class="String">"</span>]*<span class="String">"</span></span><span class="Keyword">+</span>escapeRegExp(c.end)<span class="Keyword">+</span><span class="String"><span class="String">"</span>)<span class="String">"</span></span>,<span class="String"><span class="String">"</span>g<span class="String">"</span></span>)
|
||||
<span class="line-numbers"> 579 </span> <span class="FunctionName">fn</span><span class="Keyword">:</span> <span class="Keyword">new</span> <span class="TypeName">Function</span> <span class="String"><span class="String">'</span>obj<span class="String">'</span></span>,
|
||||
<span class="line-numbers"> 580 </span> <span class="String"><span class="String">'</span>var p=[],print=function(){p.push.apply(p,arguments);};<span class="String">'</span></span> <span class="Keyword">+</span>
|
||||
<span class="line-numbers"> 581 </span> <span class="String"><span class="String">'</span>with(obj){p.push(<span class="UserDefinedConstant">\'</span><span class="String">'</span></span> <span class="Keyword">+</span>
|
||||
<span class="line-numbers"> 582 </span> str.replace(<span class="String"><span class="String">/</span>[<span class="UserDefinedConstant">\r</span><span class="UserDefinedConstant">\t</span><span class="UserDefinedConstant">\n</span>]<span class="String">/</span>g</span>, <span class="String"><span class="String">"</span> <span class="String">"</span></span>)
|
||||
<span class="line-numbers"> 583 </span> .replace(endMatch,<span class="String"><span class="String">"</span><span class="UserDefinedConstant">\t</span><span class="String">"</span></span>)
|
||||
<span class="line-numbers"> 584 </span> .split(<span class="String"><span class="String">"</span>'<span class="String">"</span></span>).join(<span class="String"><span class="String">"</span><span class="UserDefinedConstant">\\</span>'<span class="String">"</span></span>)
|
||||
<span class="line-numbers"> 585 </span> .split(<span class="String"><span class="String">"</span><span class="UserDefinedConstant">\t</span><span class="String">"</span></span>).join(<span class="String"><span class="String">"</span>'<span class="String">"</span></span>)
|
||||
<span class="line-numbers"> 586 </span> .replace(c.interpolate, <span class="String"><span class="String">"</span>',$1,'<span class="String">"</span></span>)
|
||||
<span class="line-numbers"> 587 </span> .split(c.start).join(<span class="String"><span class="String">"</span>');<span class="String">"</span></span>)
|
||||
<span class="line-numbers"> 588 </span> .split(c.end).join(<span class="String"><span class="String">"</span>p.push('<span class="String">"</span></span>) <span class="Keyword">+</span>
|
||||
<span class="line-numbers"> 589 </span> <span class="String"><span class="String">"</span>');}return p.join('');<span class="String">"</span></span>
|
||||
<span class="line-numbers"> 590 </span> <span class="Keyword">if</span> data <span class="Keyword">then</span> fn(data) <span class="Keyword">else</span> fn
|
||||
<span class="line-numbers"> 591 </span>
|
||||
<span class="line-numbers"> 592 </span>
|
||||
<span class="line-numbers"> 593 </span> <span class="Comment"><span class="Comment">#</span> ------------------------------- Aliases ----------------------------------</span>
|
||||
<span class="line-numbers"> 594 </span>
|
||||
<span class="line-numbers"> 595 </span> <span class="FunctionName">_.forEach</span><span class="Keyword">:</span> _.each
|
||||
<span class="line-numbers"> 596 </span> <span class="FunctionName">_.foldl</span><span class="Keyword">:</span> <span class="FunctionName">_.inject</span><span class="Keyword">:</span> _.reduce
|
||||
<span class="line-numbers"> 597 </span> <span class="FunctionName">_.foldr</span><span class="Keyword">:</span> _.reduceRight
|
||||
<span class="line-numbers"> 598 </span> <span class="FunctionName">_.select</span><span class="Keyword">:</span> _.filter
|
||||
<span class="line-numbers"> 599 </span> <span class="FunctionName">_.all</span><span class="Keyword">:</span> _.every
|
||||
<span class="line-numbers"> 600 </span> <span class="FunctionName">_.any</span><span class="Keyword">:</span> _.some
|
||||
<span class="line-numbers"> 601 </span> <span class="FunctionName">_.head</span><span class="Keyword">:</span> _.first
|
||||
<span class="line-numbers"> 602 </span> <span class="FunctionName">_.tail</span><span class="Keyword">:</span> _.rest
|
||||
<span class="line-numbers"> 603 </span> <span class="FunctionName">_.methods</span><span class="Keyword">:</span> _.functions
|
||||
<span class="line-numbers"> 604 </span>
|
||||
<span class="line-numbers"> 605 </span>
|
||||
<span class="line-numbers"> 606 </span> <span class="Comment"><span class="Comment">#</span> ------------------------ Setup the OOP Wrapper: --------------------------</span>
|
||||
<span class="line-numbers"> 607 </span>
|
||||
<span class="line-numbers"> 608 </span> <span class="Comment"><span class="Comment">#</span> If Underscore is called as a function, it returns a wrapped object that</span>
|
||||
<span class="line-numbers"> 609 </span> <span class="Comment"><span class="Comment">#</span> can be used OO-style. This wrapper holds altered versions of all the</span>
|
||||
<span class="line-numbers"> 610 </span> <span class="Comment"><span class="Comment">#</span> underscore functions. Wrapped objects may be chained.</span>
|
||||
<span class="line-numbers"> 611 </span> <span class="FunctionName">wrapper</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 612 </span> <span class="FunctionName">this._wrapped</span><span class="Keyword">:</span> obj
|
||||
<span class="line-numbers"> 613 </span> <span class="Variable">this</span>
|
||||
<span class="line-numbers"> 614 </span>
|
||||
<span class="line-numbers"> 615 </span>
|
||||
<span class="line-numbers"> 616 </span> <span class="Comment"><span class="Comment">#</span> Helper function to continue chaining intermediate results.</span>
|
||||
<span class="line-numbers"> 617 </span> <span class="FunctionName">result</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">obj, chain</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 618 </span> <span class="Keyword">if</span> chain <span class="Keyword">then</span> _(obj).chain() <span class="Keyword">else</span> obj
|
||||
<span class="line-numbers"> 619 </span>
|
||||
<span class="line-numbers"> 620 </span>
|
||||
<span class="line-numbers"> 621 </span> <span class="Comment"><span class="Comment">#</span> A method to easily add functions to the OOP wrapper.</span>
|
||||
<span class="line-numbers"> 622 </span> <span class="FunctionName">addToWrapper</span><span class="Keyword">:</span> <span class="FunctionArgument">(</span><span class="FunctionArgument">name, func</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 623 </span> wrapper.prototype[name]<span class="Keyword">:</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 624 </span> <span class="FunctionName">args</span><span class="Keyword">:</span> _.toArray arguments
|
||||
<span class="line-numbers"> 625 </span> unshift.call args, <span class="Variable">this</span>._wrapped
|
||||
<span class="line-numbers"> 626 </span> result func.apply(_, args), <span class="Variable">this</span>._chain
|
||||
<span class="line-numbers"> 627 </span>
|
||||
<span class="line-numbers"> 628 </span>
|
||||
<span class="line-numbers"> 629 </span> <span class="Comment"><span class="Comment">#</span> Add all of the Underscore functions to the wrapper object.</span>
|
||||
<span class="line-numbers"> 630 </span> _.mixin _
|
||||
<span class="line-numbers"> 631 </span>
|
||||
<span class="line-numbers"> 632 </span>
|
||||
<span class="line-numbers"> 633 </span> <span class="Comment"><span class="Comment">#</span> Add all mutator Array functions to the wrapper.</span>
|
||||
<span class="line-numbers"> 634 </span> _.each [<span class="String"><span class="String">'</span>pop<span class="String">'</span></span>, <span class="String"><span class="String">'</span>push<span class="String">'</span></span>, <span class="String"><span class="String">'</span>reverse<span class="String">'</span></span>, <span class="String"><span class="String">'</span>shift<span class="String">'</span></span>, <span class="String"><span class="String">'</span>sort<span class="String">'</span></span>, <span class="String"><span class="String">'</span>splice<span class="String">'</span></span>, <span class="String"><span class="String">'</span>unshift<span class="String">'</span></span>], <span class="FunctionArgument">(</span><span class="FunctionArgument">name</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 635 </span> <span class="FunctionName">method</span><span class="Keyword">:</span> Array.prototype[name]
|
||||
<span class="line-numbers"> 636 </span> wrapper.prototype[name]<span class="Keyword">:</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 637 </span> method.apply(<span class="Variable">this</span>._wrapped, arguments)
|
||||
<span class="line-numbers"> 638 </span> result(<span class="Variable">this</span>._wrapped, <span class="Variable">this</span>._chain)
|
||||
<span class="line-numbers"> 639 </span>
|
||||
<span class="line-numbers"> 640 </span>
|
||||
<span class="line-numbers"> 641 </span> <span class="Comment"><span class="Comment">#</span> Add all accessor Array functions to the wrapper.</span>
|
||||
<span class="line-numbers"> 642 </span> _.each [<span class="String"><span class="String">'</span>concat<span class="String">'</span></span>, <span class="String"><span class="String">'</span>join<span class="String">'</span></span>, <span class="String"><span class="String">'</span>slice<span class="String">'</span></span>], <span class="FunctionArgument">(</span><span class="FunctionArgument">name</span><span class="FunctionArgument">)</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 643 </span> <span class="FunctionName">method</span><span class="Keyword">:</span> Array.prototype[name]
|
||||
<span class="line-numbers"> 644 </span> wrapper.prototype[name]<span class="Keyword">:</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 645 </span> result(method.apply(<span class="Variable">this</span>._wrapped, arguments), <span class="Variable">this</span>._chain)
|
||||
<span class="line-numbers"> 646 </span>
|
||||
<span class="line-numbers"> 647 </span>
|
||||
<span class="line-numbers"> 648 </span> <span class="Comment"><span class="Comment">#</span> Start chaining a wrapped Underscore object.</span>
|
||||
<span class="line-numbers"> 649 </span> <span class="FunctionName">wrapper::chain</span><span class="Keyword">:</span> <span class="Storage">-></span>
|
||||
<span class="line-numbers"> 650 </span> <span class="FunctionName">this._chain</span><span class="Keyword">:</span> <span class="BuiltInConstant">true</span>
|
||||
<span class="line-numbers"> 651 </span> <span class="Variable">this</span>
|
||||
<span class="line-numbers"> 652 </span>
|
||||
<span class="line-numbers"> 653 </span>
|
||||
<span class="line-numbers"> 654 </span> <span class="Comment"><span class="Comment">#</span> Extracts the result from a wrapped and chained object.</span>
|
||||
<span class="line-numbers"> 655 </span> <span class="FunctionName">wrapper::value</span><span class="Keyword">:</span> <span class="Storage">-></span> <span class="Variable">this</span>._wrapped
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
16
examples/beautiful_code/binary_search.coffee
Normal file
16
examples/beautiful_code/binary_search.coffee
Normal file
@@ -0,0 +1,16 @@
|
||||
# Beautiful Code, Chapter 6.
|
||||
# The implementation of binary search that is tested.
|
||||
|
||||
# Return the index of an element in a sorted list. (or -1, if not present)
|
||||
index: (list, target) ->
|
||||
[low, high]: [0, list.length]
|
||||
while low < high
|
||||
mid: (low + high) >> 1
|
||||
val: list[mid]
|
||||
return mid if val is target
|
||||
if val < target then low: mid + 1 else high: mid
|
||||
return -1
|
||||
|
||||
puts 2 is index([10, 20, 30, 40, 50], 30)
|
||||
puts 4 is index([-97, 35, 67, 88, 1200], 1200)
|
||||
puts 0 is index([0, 45, 70], 0)
|
||||
13
examples/beautiful_code/quicksort_runtime.coffee
Normal file
13
examples/beautiful_code/quicksort_runtime.coffee
Normal file
@@ -0,0 +1,13 @@
|
||||
# Beautiful Code, Chapter 3.
|
||||
# Produces the expected runtime of Quicksort, for every integer from 1 to N.
|
||||
|
||||
runtime: (N) ->
|
||||
[sum, t]: [0, 0]
|
||||
for n in [1..N]
|
||||
sum += 2 * t
|
||||
t: n - 1 + sum / n
|
||||
t
|
||||
|
||||
puts runtime(3) is 2.6666666666666665
|
||||
puts runtime(5) is 7.4
|
||||
puts runtime(8) is 16.92142857142857
|
||||
34
examples/beautiful_code/regular_expression_matcher.coffee
Normal file
34
examples/beautiful_code/regular_expression_matcher.coffee
Normal file
@@ -0,0 +1,34 @@
|
||||
# Beautiful Code, Chapter 1.
|
||||
# Implements a regular expression matcher that supports character matches,
|
||||
# '.', '^', '$', and '*'.
|
||||
|
||||
# Search for the regexp anywhere in the text.
|
||||
match: (regexp, text) ->
|
||||
return match_here(regexp.slice(1), text) if regexp[0] is '^'
|
||||
while text
|
||||
return true if match_here(regexp, text)
|
||||
text: text.slice(1)
|
||||
false
|
||||
|
||||
# Search for the regexp at the beginning of the text.
|
||||
match_here: (regexp, text) ->
|
||||
[cur, next]: [regexp[0], regexp[1]]
|
||||
if regexp.length is 0 then return true
|
||||
if next is '*' then return match_star(cur, regexp.slice(2), text)
|
||||
if cur is '$' and not next then return text.length is 0
|
||||
if text and (cur is '.' or cur is text[0]) then return match_here(regexp.slice(1), text.slice(1))
|
||||
false
|
||||
|
||||
# Search for a kleene star match at the beginning of the text.
|
||||
match_star: (c, regexp, text) ->
|
||||
while true
|
||||
return true if match_here(regexp, text)
|
||||
return false unless text and (text[0] is c or c is '.')
|
||||
text: text.slice(1)
|
||||
|
||||
puts match("ex", "some text")
|
||||
puts match("s..t", "spit")
|
||||
puts match("^..t", "buttercup")
|
||||
puts match("i..$", "cherries")
|
||||
puts match("o*m", "vrooooommm!")
|
||||
puts match("^hel*o$", "hellllllo")
|
||||
57
examples/blocks.coffee
Normal file
57
examples/blocks.coffee
Normal file
@@ -0,0 +1,57 @@
|
||||
# After wycats' http://yehudakatz.com/2010/02/07/the-building-blocks-of-ruby/
|
||||
|
||||
# Sinatra.
|
||||
get '/hello', ->
|
||||
'Hello World'
|
||||
|
||||
|
||||
# Append.
|
||||
append: (location, data) ->
|
||||
path: new Pathname location
|
||||
throw new Error("Location does not exist") unless path.exists()
|
||||
|
||||
File.open path, 'a', (file) ->
|
||||
file.puts YAML.dump data
|
||||
|
||||
data
|
||||
|
||||
|
||||
# Rubinius' File.open implementation.
|
||||
File.open: (path, mode, block) ->
|
||||
io: new File path, mode
|
||||
|
||||
return io unless block
|
||||
|
||||
try
|
||||
block io
|
||||
finally
|
||||
try
|
||||
io.close() unless io.closed()
|
||||
catch error
|
||||
# nothing, just swallow them.
|
||||
|
||||
|
||||
# Write.
|
||||
write: (location, data) ->
|
||||
path = new Pathname location
|
||||
raise "Location does not exist" unless path.exists()
|
||||
|
||||
File.open path, 'w', (file) ->
|
||||
return false if Digest.MD5.hexdigest(file.read()) is data.hash()
|
||||
file.puts YAML.dump data
|
||||
true
|
||||
|
||||
|
||||
# Rails' respond_to.
|
||||
index: ->
|
||||
people: Person.find 'all'
|
||||
|
||||
respond_to (format) ->
|
||||
format.html()
|
||||
format.xml -> render { xml: people.xml() }
|
||||
|
||||
|
||||
# Synchronization.
|
||||
synchronize: (block) ->
|
||||
lock()
|
||||
try block() finally unlock()
|
||||
@@ -1,16 +1,16 @@
|
||||
# Functions:
|
||||
square: x => x * x.
|
||||
square: (x) -> x * x
|
||||
|
||||
sum: x, y => x + y.
|
||||
sum: (x, y) -> x + y
|
||||
|
||||
odd: x => x % 2 is 0.
|
||||
odd: (x) -> x % 2 isnt 0
|
||||
|
||||
even: x => x % 2 isnt 0.
|
||||
even: (x) -> x % 2 is 0
|
||||
|
||||
run_loop: =>
|
||||
fire_events( e => e.stopPropagation(). )
|
||||
run_loop: ->
|
||||
fire_events((e) -> e.stopPropagation())
|
||||
listen()
|
||||
wait().
|
||||
wait()
|
||||
|
||||
# Objects:
|
||||
dense_object_literal: {one: 1, two: 2, three: 3}
|
||||
@@ -22,14 +22,14 @@ spaced_out_multiline_object: {
|
||||
three: new Idea()
|
||||
|
||||
inner_obj: {
|
||||
freedom: => _.freedom().
|
||||
freedom: -> _.freedom()
|
||||
}
|
||||
}
|
||||
|
||||
# Arrays:
|
||||
stooges : [{moe: 45}, {curly: 43}, {larry: 46}]
|
||||
stooges: [{moe: 45}, {curly: 43}, {larry: 46}]
|
||||
|
||||
exponents : [x => x., x => x * x., x => x * x * x.]
|
||||
exponents: [(x) -> x, (x) -> x * x, (x) -> x * x * x]
|
||||
|
||||
empty: []
|
||||
|
||||
@@ -45,21 +45,21 @@ if submarine.shields_up
|
||||
else if submarine.sinking
|
||||
abandon_ship()
|
||||
else
|
||||
run_away().
|
||||
run_away()
|
||||
|
||||
eldest: if 25 > 21 then liz else marge.
|
||||
eldest: if 25 > 21 then liz else marge
|
||||
|
||||
decoration: medal_of_honor if war_hero
|
||||
|
||||
go_to_sleep() unless coffee
|
||||
|
||||
# Returning early:
|
||||
race: =>
|
||||
race: ->
|
||||
run()
|
||||
walk()
|
||||
crawl()
|
||||
if tired then return sleep().
|
||||
race().
|
||||
if tired then return sleep()
|
||||
race()
|
||||
|
||||
# Conditional assignment:
|
||||
good ||= evil
|
||||
@@ -81,58 +81,58 @@ try
|
||||
dogs_and_cats_living_together()
|
||||
throw "up"
|
||||
catch error
|
||||
print( error )
|
||||
print(error)
|
||||
finally
|
||||
clean_up().
|
||||
clean_up()
|
||||
|
||||
try all_hell_breaks_loose() catch error print(error) finally clean_up().
|
||||
try all_hell_breaks_loose() catch error then print(error) finally clean_up()
|
||||
|
||||
# While loops, break and continue.
|
||||
while demand > supply
|
||||
sell()
|
||||
restock().
|
||||
restock()
|
||||
|
||||
while supply > demand then buy().
|
||||
while supply > demand then buy()
|
||||
|
||||
while true
|
||||
break if broken
|
||||
continue if continuing.
|
||||
continue if continuing
|
||||
|
||||
# Unary operators.
|
||||
!!true
|
||||
|
||||
# Lexical scoping.
|
||||
a: 5
|
||||
change_a_and_set_b: =>
|
||||
a: 10
|
||||
b: 15.
|
||||
b: 20
|
||||
v_1: 5
|
||||
change_a_and_set_b: ->
|
||||
v_1: 10
|
||||
v_2: 15
|
||||
v_2: 20
|
||||
|
||||
# Array comprehensions.
|
||||
supper: food.capitalize() for food in ['toast', 'cheese', 'wine'].
|
||||
supper: food.capitalize() for food in ['toast', 'cheese', 'wine']
|
||||
|
||||
drink(bottle) for bottle, i in ['soda', 'wine', 'lemonade'] if even(i).
|
||||
drink(bottle) for bottle, i in ['soda', 'wine', 'lemonade'] when even(i)
|
||||
|
||||
# Switch statements ("else" serves as a default).
|
||||
activity: switch day
|
||||
when "Tuesday" then eat_breakfast()
|
||||
when "Sunday" then go_to_church()
|
||||
when "Saturday" then go_to_the_park()
|
||||
when "Wednesday"
|
||||
if day is bingo_day
|
||||
go_to_bingo()
|
||||
else
|
||||
eat_breakfast()
|
||||
go_to_work()
|
||||
eat_dinner().
|
||||
else go_to_work().
|
||||
when "Tuesday" then eat_breakfast()
|
||||
when "Sunday" then go_to_church()
|
||||
when "Saturday" then go_to_the_park()
|
||||
when "Wednesday"
|
||||
if day is bingo_day
|
||||
go_to_bingo()
|
||||
else
|
||||
eat_breakfast()
|
||||
go_to_work()
|
||||
eat_dinner()
|
||||
else go_to_work()
|
||||
|
||||
# Semicolons can optionally be used instead of newlines.
|
||||
wednesday: => eat_breakfast(); go_to_work(); eat_dinner(); .
|
||||
wednesday: -> eat_breakfast(); go_to_work(); eat_dinner()
|
||||
|
||||
# Array slice literals.
|
||||
zero_to_nine: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
|
||||
three_to_six: zero_to_nine[3, 6]
|
||||
three_to_six: zero_to_nine[3..6]
|
||||
|
||||
# Multiline strings with inner quotes.
|
||||
story: "Lorem ipsum dolor \"sit\" amet, consectetuer adipiscing elit,
|
||||
@@ -140,24 +140,28 @@ sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna
|
||||
aliquam erat volutpat. Ut wisi enim ad."
|
||||
|
||||
# Inheritance and calling super.
|
||||
Animal: => .
|
||||
Animal.prototype.move: meters =>
|
||||
alert(this.name + " moved " + meters + "m.").
|
||||
class Animal
|
||||
move: (meters) ->
|
||||
alert this.name + " moved " + meters + "m."
|
||||
|
||||
Snake: name => this.name: name.
|
||||
Snake extends Animal
|
||||
Snake.prototype.move: =>
|
||||
alert('Slithering...')
|
||||
super(5).
|
||||
class Snake extends Animal
|
||||
constructor: (name) ->
|
||||
@name: name
|
||||
|
||||
Horse: name => this.name: name.
|
||||
Horse extends Animal
|
||||
Horse.prototype.move: =>
|
||||
alert('Galloping...')
|
||||
super(45).
|
||||
move: ->
|
||||
alert 'Slithering...'
|
||||
super 5
|
||||
|
||||
sam: new Snake("Sammy the Snake")
|
||||
tom: new Horse("Tommy the Horse")
|
||||
class Horse extends Animal
|
||||
constructor: (name) ->
|
||||
@name: name
|
||||
|
||||
move: ->
|
||||
alert 'Galloping...'
|
||||
super 45
|
||||
|
||||
sam: new Snake "Sammy the Snake"
|
||||
tom: new Horse "Tommy the Horse"
|
||||
|
||||
sam.move()
|
||||
tom.move()
|
||||
|
||||
4
examples/computer_science/README
Normal file
4
examples/computer_science/README
Normal file
@@ -0,0 +1,4 @@
|
||||
Ported from Nicholas Zakas' collection of computer science fundamentals, written
|
||||
in JavaScript. Originals available here:
|
||||
|
||||
http://github.com/nzakas/computer-science-in-javascript
|
||||
25
examples/computer_science/binary_search.coffee
Normal file
25
examples/computer_science/binary_search.coffee
Normal file
@@ -0,0 +1,25 @@
|
||||
# Uses a binary search algorithm to locate a value in the specified array.
|
||||
binary_search: (items, value) ->
|
||||
|
||||
start: 0
|
||||
stop: items.length - 1
|
||||
pivot: Math.floor((start + stop) / 2)
|
||||
|
||||
while items[pivot] isnt value and start < stop
|
||||
|
||||
# Adjust the search area.
|
||||
stop: pivot - 1 if value < items[pivot]
|
||||
start: pivot + 1 if value > items[pivot]
|
||||
|
||||
# Recalculate the pivot.
|
||||
pivot: Math.floor((stop + start) / 2)
|
||||
|
||||
# Make sure we've found the correct value.
|
||||
if items[pivot] is value then pivot else -1
|
||||
|
||||
|
||||
# Test the function.
|
||||
puts(2 is binary_search([10, 20, 30, 40, 50], 30))
|
||||
puts(4 is binary_search([-97, 35, 67, 88, 1200], 1200))
|
||||
puts(0 is binary_search([0, 45, 70], 0))
|
||||
puts(-1 is binary_search([0, 45, 70], 10))
|
||||
11
examples/computer_science/bubble_sort.coffee
Normal file
11
examples/computer_science/bubble_sort.coffee
Normal file
@@ -0,0 +1,11 @@
|
||||
# A bubble sort implementation, sorting the given array in-place.
|
||||
bubble_sort: (list) ->
|
||||
for i in [0...list.length]
|
||||
for j in [0...list.length - i]
|
||||
[list[j], list[j+1]]: [list[j+1], list[j]] if list[j] > list[j+1]
|
||||
list
|
||||
|
||||
|
||||
# Test the function.
|
||||
puts(bubble_sort([3, 2, 1]).join(' ') is '1 2 3')
|
||||
puts(bubble_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9')
|
||||
108
examples/computer_science/linked_list.coffee
Normal file
108
examples/computer_science/linked_list.coffee
Normal file
@@ -0,0 +1,108 @@
|
||||
# "Classic" linked list implementation that doesn't keep track of its size.
|
||||
class LinkedList
|
||||
|
||||
constructor: ->
|
||||
this._head: null # Pointer to the first item in the list.
|
||||
|
||||
|
||||
# Appends some data to the end of the list. This method traverses the existing
|
||||
# list and places the value at the end in a new node.
|
||||
add: (data) ->
|
||||
|
||||
# Create a new node object to wrap the data.
|
||||
node: {data: data, next: null}
|
||||
|
||||
current: this._head ||= node
|
||||
|
||||
if this._head isnt node
|
||||
current: current.next while current.next
|
||||
current.next: node
|
||||
|
||||
this
|
||||
|
||||
|
||||
# Retrieves the data at the given position in the list.
|
||||
item: (index) ->
|
||||
|
||||
# Check for out-of-bounds values.
|
||||
return null if index < 0
|
||||
|
||||
current: this._head or null
|
||||
i: -1
|
||||
|
||||
# Advance through the list.
|
||||
current: current.next while current and index > (i += 1)
|
||||
|
||||
# Return null if we've reached the end.
|
||||
current and current.data
|
||||
|
||||
|
||||
# Remove the item from the given location in the list.
|
||||
remove: (index) ->
|
||||
|
||||
# Check for out-of-bounds values.
|
||||
return null if index < 0
|
||||
|
||||
current: this._head or null
|
||||
i: -1
|
||||
|
||||
# Special case: removing the first item.
|
||||
if index is 0
|
||||
this._head: current.next
|
||||
else
|
||||
|
||||
# Find the right location.
|
||||
[previous, current]: [current, current.next] while index > (i += 1)
|
||||
|
||||
# Skip over the item to remove.
|
||||
previous.next: current.next
|
||||
|
||||
# Return the value.
|
||||
current and current.data
|
||||
|
||||
|
||||
# Calculate the number of items in the list.
|
||||
size: ->
|
||||
current: this._head
|
||||
count: 0
|
||||
|
||||
while current
|
||||
count += 1
|
||||
current: current.next
|
||||
|
||||
count
|
||||
|
||||
|
||||
# Convert the list into an array.
|
||||
toArray: ->
|
||||
result: []
|
||||
current: this._head
|
||||
|
||||
while current
|
||||
result.push(current.data)
|
||||
current: current.next
|
||||
|
||||
result
|
||||
|
||||
|
||||
# The string representation of the linked list.
|
||||
toString: -> this.toArray().toString()
|
||||
|
||||
|
||||
# Tests.
|
||||
list: new LinkedList()
|
||||
|
||||
list.add("Hi")
|
||||
puts(list.size() is 1)
|
||||
puts(list.item(0) is "Hi")
|
||||
puts(list.item(1) is null)
|
||||
|
||||
list: new LinkedList()
|
||||
list.add("zero").add("one").add("two")
|
||||
puts(list.size() is 3)
|
||||
puts(list.item(2) is "two")
|
||||
puts(list.remove(1) is "one")
|
||||
puts(list.item(0) is "zero")
|
||||
puts(list.item(1) is "two")
|
||||
puts(list.size() is 2)
|
||||
puts(list.item(-10) is null)
|
||||
36
examples/computer_science/luhn_algorithm.coffee
Normal file
36
examples/computer_science/luhn_algorithm.coffee
Normal file
@@ -0,0 +1,36 @@
|
||||
# Use the Luhn algorithm to validate a numeric identifier, such as credit card
|
||||
# numbers, national insurance numbers, etc.
|
||||
# See: http://en.wikipedia.org/wiki/Luhn_algorithm
|
||||
|
||||
is_valid_identifier: (identifier) ->
|
||||
|
||||
sum: 0
|
||||
alt: false
|
||||
|
||||
for i in [(identifier.length - 1)..0]
|
||||
|
||||
# Get the next digit.
|
||||
num: parseInt(identifier.charAt(i), 10)
|
||||
|
||||
# If it's not a valid number, abort.
|
||||
return false if isNaN(num)
|
||||
|
||||
# If it's an alternate number...
|
||||
if alt
|
||||
num *= 2
|
||||
num: (num % 10) + 1 if num > 9
|
||||
|
||||
# Flip the alternate bit.
|
||||
alt: !alt
|
||||
|
||||
# Add to the rest of the sum.
|
||||
sum += num
|
||||
|
||||
# Determine if it's valid.
|
||||
sum % 10 is 0
|
||||
|
||||
|
||||
# Tests.
|
||||
puts(is_valid_identifier("49927398716") is true)
|
||||
puts(is_valid_identifier("4408041234567893") is true)
|
||||
puts(is_valid_identifier("4408041234567890") is false)
|
||||
19
examples/computer_science/merge_sort.coffee
Normal file
19
examples/computer_science/merge_sort.coffee
Normal file
@@ -0,0 +1,19 @@
|
||||
# Sorts an array in ascending natural order using merge sort.
|
||||
merge_sort: (list) ->
|
||||
|
||||
return list if list.length is 1
|
||||
|
||||
result: []
|
||||
pivot: Math.floor(list.length / 2)
|
||||
left: merge_sort(list.slice(0, pivot))
|
||||
right: merge_sort(list.slice(pivot))
|
||||
|
||||
while left.length and right.length
|
||||
result.push(if left[0] < right[0] then left.shift() else right.shift())
|
||||
|
||||
result.concat(left).concat(right)
|
||||
|
||||
|
||||
# Test the function.
|
||||
puts(merge_sort([3, 2, 1]).join(' ') is '1 2 3')
|
||||
puts(merge_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9')
|
||||
23
examples/computer_science/selection_sort.coffee
Normal file
23
examples/computer_science/selection_sort.coffee
Normal file
@@ -0,0 +1,23 @@
|
||||
# An in-place selection sort.
|
||||
selection_sort: (list) ->
|
||||
len: list.length
|
||||
|
||||
# For each item in the list.
|
||||
for i in [0...len]
|
||||
|
||||
# Set the minimum to this position.
|
||||
min: i
|
||||
|
||||
# Check the rest of the array to see if anything is smaller.
|
||||
(min: j if list[j] < list[min]) for j in [(i+1)...len]
|
||||
|
||||
# Swap if a smaller item has been found.
|
||||
[list[i], list[min]]: [list[min], list[i]] if i isnt min
|
||||
|
||||
# The list is now sorted.
|
||||
list
|
||||
|
||||
|
||||
# Test the function.
|
||||
puts(selection_sort([3, 2, 1]).join(' ') is '1 2 3')
|
||||
puts(selection_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9')
|
||||
@@ -1,72 +0,0 @@
|
||||
# Document Model
|
||||
dc.model.Document: dc.Model.extend({
|
||||
|
||||
constructor: attributes => this.base(attributes).
|
||||
|
||||
# For display, show either the highlighted search results, or the summary,
|
||||
# if no highlights are available.
|
||||
# The import process will take care of this in the future, but the inline
|
||||
# version of the summary has all runs of whitespace squeezed out.
|
||||
displaySummary: =>
|
||||
text: this.get('highlight') or this.get('summary') or ''
|
||||
text and text.replace(/\s+/g, ' ').
|
||||
|
||||
# Return a list of the document's metadata. Think about caching this on the
|
||||
# document by binding to Metadata, instead of on-the-fly.
|
||||
metadata: =>
|
||||
docId: this.id
|
||||
_.select(Metadata.models()
|
||||
meta => _.any(meta.get('instances')
|
||||
instance => instance.document_id is docId.).).
|
||||
|
||||
bookmark: pageNumber =>
|
||||
bookmark: new dc.model.Bookmark({title: this.get('title'), page_number: pageNumber, document_id: this.id})
|
||||
Bookmarks.create(bookmark).
|
||||
|
||||
# Inspect.
|
||||
toString: => 'Document ' + this.id + ' "' + this.get('title') + '"'.
|
||||
|
||||
})
|
||||
|
||||
# Document Set
|
||||
dc.model.DocumentSet: dc.model.RESTfulSet.extend({
|
||||
|
||||
resource: 'documents'
|
||||
|
||||
SELECTION_CHANGED: 'documents:selection_changed'
|
||||
|
||||
constructor: options =>
|
||||
this.base(options)
|
||||
_.bindAll(this, 'downloadSelectedViewers', 'downloadSelectedPDF', 'downloadSelectedFullText').
|
||||
|
||||
selected: => _.select(this.models(), m => m.get('selected').).
|
||||
|
||||
selectedIds: => _.pluck(this.selected(), 'id').
|
||||
|
||||
countSelected: => this.selected().length.
|
||||
|
||||
downloadSelectedViewers: =>
|
||||
dc.app.download('/download/' + this.selectedIds().join('/') + '/document_viewer.zip').
|
||||
|
||||
downloadSelectedPDF: =>
|
||||
if this.countSelected() <= 1 then return window.open(this.selected()[0].get('pdf_url')).
|
||||
dc.app.download('/download/' + this.selectedIds().join('/') + '/document_pdfs.zip').
|
||||
|
||||
downloadSelectedFullText: =>
|
||||
if this.countSelected() <= 1 then return window.open(this.selected()[0].get('full_text_url')).
|
||||
dc.app.download('/download/' + this.selectedIds().join('/') + '/document_text.zip').
|
||||
|
||||
# We override "_onModelEvent" to fire selection changed events when documents
|
||||
# change their selected state.
|
||||
_onModelEvent: e, model =>
|
||||
this.base(e, model)
|
||||
fire: e == dc.Model.CHANGED and model.hasChanged('selected')
|
||||
if fire then _.defer(_(this.fire).bind(this, this.SELECTION_CHANGED, this))..
|
||||
|
||||
})
|
||||
|
||||
# The main set of Documents, used by the search tab.
|
||||
window.Documents: new dc.model.DocumentSet()
|
||||
|
||||
# The set of documents that is used to look at a particular label.
|
||||
dc.app.LabeledDocuments: new dc.model.DocumentSet()
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
# ['toast', 'cheese', 'wine'].each { |food| print food.capitalize }
|
||||
|
||||
['toast', 'wine', 'cheese'].each( food => print(food.capitalize()). )
|
||||
['toast', 'wine', 'cheese'].each (food) -> print(food.capitalize())
|
||||
|
||||
|
||||
|
||||
@@ -14,10 +14,43 @@
|
||||
# end
|
||||
|
||||
LotteryTicket: {
|
||||
get_picks: => this.picks.
|
||||
set_picks: nums => this.picks: nums.
|
||||
get_purchase: => this.purchase.
|
||||
set_purchase: amount => this.purchase: amount.
|
||||
get_picks: -> this.picks
|
||||
set_picks: (nums) -> this.picks: nums
|
||||
get_purchase: -> this.purchase
|
||||
set_purchase: (amount) -> this.purchase: amount
|
||||
}
|
||||
|
||||
|
||||
|
||||
# class << LotteryDraw
|
||||
# def play
|
||||
# result = LotteryTicket.new_random
|
||||
# winners = {}
|
||||
# @@tickets.each do |buyer, ticket_list|
|
||||
# ticket_list.each do |ticket|
|
||||
# score = ticket.score( result )
|
||||
# next if score.zero?
|
||||
# winners[buyer] ||= []
|
||||
# winners[buyer] << [ ticket, score ]
|
||||
# end
|
||||
# end
|
||||
# @@tickets.clear
|
||||
# winners
|
||||
# end
|
||||
# end
|
||||
|
||||
LotteryDraw: {
|
||||
play: ->
|
||||
result: LotteryTicket.new_random()
|
||||
winners: {}
|
||||
this.tickets.each (buyer, ticket_list) ->
|
||||
ticket_list.each (ticket) ->
|
||||
score: ticket.score(result)
|
||||
return if score is 0
|
||||
winners[buyer] ||= []
|
||||
winners[buyer].push([ticket, score])
|
||||
this.tickets: {}
|
||||
winners
|
||||
}
|
||||
|
||||
|
||||
@@ -32,9 +65,9 @@ LotteryTicket: {
|
||||
# end
|
||||
|
||||
WishScanner: {
|
||||
scan_for_a_wish: =>
|
||||
wish: this.read().detect( thought => thought.index('wish: ') is 0. )
|
||||
wish.replace('wish: ', '').
|
||||
scan_for_a_wish: ->
|
||||
wish: this.read().detect((thought) -> thought.index('wish: ') is 0)
|
||||
wish.replace('wish: ', '')
|
||||
}
|
||||
|
||||
|
||||
@@ -78,29 +111,29 @@ WishScanner: {
|
||||
Creature : {
|
||||
|
||||
# This method applies a hit taken during a fight.
|
||||
hit: damage =>
|
||||
p_up: Math.rand( this.charisma )
|
||||
hit: (damage) ->
|
||||
p_up: Math.rand(this.charisma)
|
||||
if p_up % 9 is 7
|
||||
this.life += p_up / 4
|
||||
puts( "[" + this.name + " magick powers up " + p_up + "!]" ).
|
||||
puts("[" + this.name + " magick powers up " + p_up + "!]")
|
||||
this.life -= damage
|
||||
if this.life <= 0 then puts( "[" + this.name + " has died.]" )..
|
||||
if this.life <= 0 then puts("[" + this.name + " has died.]")
|
||||
|
||||
# This method takes one turn in a fight.
|
||||
fight: enemy, weapon =>
|
||||
if this.life <= 0 then return puts( "[" + this.name + "is too dead to fight!]" ).
|
||||
fight: (enemy, weapon) ->
|
||||
if this.life <= 0 then return puts("[" + this.name + "is too dead to fight!]")
|
||||
|
||||
# Attack the opponent.
|
||||
your_hit: Math.rand( this.strength + weapon )
|
||||
puts( "[You hit with " + your_hit + "points of damage!]" )
|
||||
enemy.hit( your_hit )
|
||||
your_hit: Math.rand(this.strength + weapon)
|
||||
puts("[You hit with " + your_hit + "points of damage!]")
|
||||
enemy.hit(your_hit)
|
||||
|
||||
# Retaliation.
|
||||
puts( enemy )
|
||||
puts(enemy)
|
||||
if enemy.life > 0
|
||||
enemy_hit: Math.rand( enemy.strength + enemy.weapon )
|
||||
puts( "[Your enemy hit with " + enemy_hit + "points of damage!]" )
|
||||
this.hit( enemy_hit )..
|
||||
enemy_hit: Math.rand(enemy.strength + enemy.weapon)
|
||||
puts("[Your enemy hit with " + enemy_hit + "points of damage!]")
|
||||
this.hit(enemy_hit)
|
||||
|
||||
}
|
||||
|
||||
@@ -123,12 +156,12 @@ Creature : {
|
||||
# Get evil idea and swap in code words
|
||||
print("Enter your new idea: ")
|
||||
idea: gets()
|
||||
code_words.each( real, code => idea.replace(real, code). )
|
||||
code_words.each((real, code) -> idea.replace(real, code))
|
||||
|
||||
# Save the jibberish to a new file
|
||||
print("File encoded. Please enter a name for this idea: ")
|
||||
idea_name: gets().strip()
|
||||
File.open("idea-" + idea_name + '.txt', 'w', file => file.write(idea). )
|
||||
File.open("idea-" + idea_name + '.txt', 'w', (file) -> file.write(idea))
|
||||
|
||||
|
||||
|
||||
@@ -144,10 +177,10 @@ File.open("idea-" + idea_name + '.txt', 'w', file => file.write(idea). )
|
||||
# end
|
||||
# end
|
||||
|
||||
wipe_mutterings_from: sentence =>
|
||||
wipe_mutterings_from: (sentence) ->
|
||||
throw new Error("cannot wipe mutterings") unless sentence.indexOf
|
||||
while sentence.indexOf('(') >= 0
|
||||
open: sentence.indexOf('(') - 1
|
||||
close: sentence.indexOf(')') + 1
|
||||
sentence: sentence[0, open] + sentence[close, sentence.length].
|
||||
sentence.
|
||||
sentence: sentence[0..open] + sentence[close..sentence.length]
|
||||
sentence
|
||||
206
examples/potion.coffee
Normal file
206
examples/potion.coffee
Normal file
@@ -0,0 +1,206 @@
|
||||
# Examples from _why's Potion, the Readme and "Potion: A Short Pamphlet".
|
||||
|
||||
# 5 times: "Odelay!" print.
|
||||
|
||||
print("Odelay!") for i in [1..5]
|
||||
|
||||
|
||||
# add = (x, y): x + y.
|
||||
# add(2, 4) string print
|
||||
|
||||
add: (x, y) -> x + y
|
||||
print(add(2, 4))
|
||||
|
||||
|
||||
# loop: 'quaff' print.
|
||||
|
||||
while true
|
||||
print('quaff')
|
||||
|
||||
|
||||
# ('cheese', 'bread', 'mayo') at (1) print
|
||||
|
||||
print(['cheese', 'bread', 'mayo'][1])
|
||||
|
||||
|
||||
# (language='Potion', pointless=true) at (key='language') print
|
||||
|
||||
print({language: 'Potion', pointless: true}['language'])
|
||||
|
||||
|
||||
# minus = (x, y): x - y.
|
||||
# minus (y=10, x=6)
|
||||
|
||||
minus: (x, y) -> x - y
|
||||
minus(6, 10)
|
||||
|
||||
|
||||
# foods = ('cheese', 'bread', 'mayo')
|
||||
# foods (2)
|
||||
|
||||
foods: ['cheese', 'bread', 'mayo']
|
||||
foods[2]
|
||||
|
||||
|
||||
# (dog='canine', cat='feline', fox='vulpine') each (key, val):
|
||||
# (key, ' is a ', val) join print.
|
||||
|
||||
for key, val of {dog: 'canine', cat: 'feline', fox: 'vulpine'}
|
||||
print(key + ' is a ' + val)
|
||||
|
||||
|
||||
# Person = class: /name, /age, /sex.
|
||||
# Person print = ():
|
||||
# ('My name is ', /name, '.') join print.
|
||||
|
||||
class Person
|
||||
print: ->
|
||||
print 'My name is ' + this.name + '.'
|
||||
|
||||
|
||||
# p = Person ()
|
||||
# p /name string print
|
||||
|
||||
p: new Person()
|
||||
print p.name
|
||||
|
||||
|
||||
# Policeman = Person class (rank): /rank = rank.
|
||||
# Policeman print = ():
|
||||
# ('My name is ', /name, ' and I'm a ', /rank, '.') join print.
|
||||
#
|
||||
# Policeman ('Constable') print
|
||||
|
||||
class Policeman extends Person
|
||||
constructor: (rank) ->
|
||||
@rank: rank
|
||||
print: ->
|
||||
print 'My name is ' + this.name + " and I'm a " + this.rank + '.'
|
||||
|
||||
print new Policeman 'Constable'
|
||||
|
||||
|
||||
# app = [window (width=200, height=400)
|
||||
# [para 'Welcome.', button 'OK']]
|
||||
# app first name
|
||||
|
||||
app = {
|
||||
window: {width: 200, height: 200}
|
||||
para: 'Welcome.'
|
||||
button: 'OK'
|
||||
}
|
||||
app.window
|
||||
|
||||
|
||||
# x = 1
|
||||
# y = 2
|
||||
#
|
||||
# x = 1, y = 2
|
||||
|
||||
x: 1
|
||||
y: 2
|
||||
|
||||
x: 1; y: 2
|
||||
|
||||
|
||||
# table = (language='Potion'
|
||||
# pointless=true)
|
||||
|
||||
table: {
|
||||
language: 'Potion'
|
||||
pointless: yes
|
||||
}
|
||||
|
||||
|
||||
# # this foul business...
|
||||
# String length = (): 10.
|
||||
|
||||
# this foul business...
|
||||
String::length: -> 10
|
||||
|
||||
|
||||
# block = :
|
||||
# 'potion' print.
|
||||
|
||||
block: ->
|
||||
print('potion')
|
||||
|
||||
|
||||
# if (age > 100): 'ancient'.
|
||||
|
||||
if age > 100 then 'ancient'
|
||||
|
||||
|
||||
# author =
|
||||
# if (title == 'Jonathan Strange & Mr. Norrell'):
|
||||
# 'Susanna Clarke'.
|
||||
# elsif (title == 'The Star Diaries'):
|
||||
# 'Stanislaw Lem'.
|
||||
# elsif (title == 'The Slynx'):
|
||||
# 'Tatyana Tolstaya'.
|
||||
# else:
|
||||
# '... probably Philip K. Dick'.
|
||||
|
||||
switch author
|
||||
when 'Jonathan Strange & Mr. Norrell'
|
||||
'Susanna Clarke'
|
||||
when 'The Star Diaries'
|
||||
'Stanislaw Lem'
|
||||
when 'The Slynx'
|
||||
'Tatyana Tolstaya'
|
||||
else
|
||||
'... probably Philip K. Dick'
|
||||
|
||||
|
||||
# count = 8
|
||||
# while (count > 0):
|
||||
# 'quaff' print
|
||||
# count--.
|
||||
|
||||
count: 8
|
||||
while count > 0
|
||||
print('quaff')
|
||||
count--
|
||||
|
||||
|
||||
# 1 to 5 (a):
|
||||
# a string print.
|
||||
|
||||
print(a) for a in [1..5]
|
||||
|
||||
|
||||
# if (3 ?gender):
|
||||
# "Huh? Numbers are sexed? That's amazing." print.
|
||||
|
||||
if (3).gender?
|
||||
print("Huh? Numbers are sexed? That's amazing.")
|
||||
|
||||
|
||||
# HomePage get = (url):
|
||||
# session = url query ? at ('session').
|
||||
|
||||
HomePage::get: (url) ->
|
||||
session: url.query.session if url.query?
|
||||
|
||||
|
||||
# BTree = class: /left, /right.
|
||||
# b = BTree ()
|
||||
# b /left = BTree ()
|
||||
# b /right = BTree ()
|
||||
|
||||
BTree: ->
|
||||
b: new BTree()
|
||||
b.left: new BTree()
|
||||
b.right: new BTree()
|
||||
|
||||
|
||||
# BTree = class: /left, /right.
|
||||
# b = BTree ()
|
||||
#
|
||||
# if (b ? /left):
|
||||
# 'left path found!' print.
|
||||
|
||||
BTree: ->
|
||||
b: new BTree()
|
||||
|
||||
print('left path found!') if b.left?
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user