Skip to content

alxpborges/Sugar.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

Releases

No releases published

Packages

No packages published