improve commonjs packaging detection

root.require is not always available (eg. in browserify and node) so the
detection fails.  require should always be a function in scope within a
module, though.
Merge pull request #106 from olark/fix-commonjs-detection

fix commonjs packaging detection