-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
25 lines (22 loc) · 849 Bytes
/
README
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
Mini tutorial on http://art543484.narod.ru/sugar
Maybe = Sugar(arguments, object); //New sugar
Maybe = Maybe(pattern) //Add pattern
Maybe = Maybe.wrong(message) //If function called with unexpected number of arguments then Maybe throw new error with message
Maybe = Maybe.def(object) //Define default arguments
result = Maybe.end(view, function) //Call function
Example:
function Point () {
sugar(arguments, this)
(['x','y'])
([['x','y']])
([{x:'x',y:'y'}])
.wrong('Point - Unexpected number of arguments')
.end('x,y', function(x,y){
this.x = x == null ? null : Number(x);
this.y = y == null ? null : Number(y);
});
};
Point(2,3);
Point([2,3]);
Point({x:2, y:3});
Point(4); //Error: Point - Unexpected number of arguments