Just as it sounds. Using Sugar.js is kind of adding some sugar to our code. Sugar.js isn’t a framework for creating magnificent user interface, one page web application or manipulating the DOM. Sugar.js is a simple libray that provides us with lots of useful functions we can use in order to write shorter code.
The following code sample shows how simple it is to use Sugar.js. It includes a small demo for calling one of Sugar.js functions that allows us getting a simple new array based on an existing one.
<!DOCTYPE html> <html> <head> <title>sugar demo</title> <script type="text/javascript" src="sugar-full.min.js"></script> </head> <body> <script type="text/javascript"> var firstVec = [101,200,303,402,505]; var secondVec = firstVec.last(3); for(var i=0; i<secondVec.length; i++) { document.write("<br>"+secondVec[i]); } </script> </body> </html>
The following video clip overviews the above code sample, shows its execution and explains it step by step.
You can find more training material including video clips, code samples and slides for learning this library in my free (for personal and academic usage) online courses at http://abelski.lifemichael.com.