making commonjs and amd compat

- using window instead of  since it's not always the window
- trying to export for commonjs and amd first before attaching function to window
creating example to show that this now works with commonjs

- install beefy: npm install -g beefy
- cd commonjs && beefy --live