Playing around with JavaScript

Feeling bored at office so I decide to wrap the first lib and make some possible improvements.. I stopped at line 940.