/
index.haml
106 lines (86 loc) · 2.52 KB
/
index.haml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
:plain
---
layout: default
---
%h1 JS2
%h2 Javascript Syntactic Sugar
%p
JS2 is for anyone who writes Javascript whether it be for browsers or for serverside scripting (nodejs and ringojs). JS2 provides superset of javascript (which is backwards compatible with normal javascript) for features like: classes, inheritance, methods, currying, and shorthand sugar for common patterns.
%h2 Author
%p
Jeff Su (me@jeffsu.com)
%h2 Try
%textarea.code!
:plain
class Hello {
function world() {
return "hello";
}
}
class Foo extends Hello {
function world() {
return this.$super() + " world";
}
}
var foo = new Foo();
alert(foo.world());
var arr = [ 1, 2, 3, 4 ];
alert(js2(arr).reduce(\#{ return $1 + $2 }));
%input.run{ :type => 'button', :value => 'Run' }
%h2 Install
%p
%h3 Browser
%p There are 2 ways to run js2 in the web browser. The first is to import js2 files and compile them on the client side web browsers, but this is slow and should only be used for testing. The second is to compile js2 on the server side and then run the raw javascript on the web browser.
%strong Option 1 (easy):
Download
%a{ :href => '/js2/javascript/js2-full.js' } js2-full.js
and include it in a script tag. Here is some sample code:
%pre!
JS2.require("/javascripts/my-code.js2", function (code) { eval(code) });
%strong Option 2 (preferred):
Download
%a{ :href => '/js2/javascript/js2.js' } js2.js
and include it in a script tag. Just make sure you include it before any compiled js2 code.
%h3 NodeJS
%pre!
npm install js2
%h3 RingoJS
%pre!
ringo-admin install jeffsu/js2
%h3 Ruby
%pre!
gem install js2 --pre
%h2 Docs
%ul
%li
%a{ :href => 'http://github.com/jeffsu/js2/wiki' } Introduction
%li
%a{ :href => 'http://github.com/jeffsu/js2/wiki/Installation' } Installation
%li
%a{ :href => 'http://github.com/jeffsu/js2/wiki/Getting-Started' } Getting Started
%h2 Source
%p
Clone it with
%a{ :href => 'http://git-scm.com' } git
by running
%pre!
git clone git://github.com/jeffsu/js2
%p
Download Project here:
%a{ :href => 'http://github.com/jeffsu/js2/zipball/master' } zip
or
%a{ :href => 'http://github.com/jeffsu/js2/tarball/master' } tar
%style
:sass
.code
width: 100%
font-family: monospace
height: 350px
padding: 4px
font-size: 1.2em
:javascript
$(function () {
$('.run').click(function () {
eval(js2.render($('.code').val()));
});
});