Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CommonJS/RequireJS/AMD support #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

wellcaffeinated
Copy link

Hi
I've patched the code so that it should work as an AMD Module (with requireJS), a node module (as per commonJS syntax), or a browser global.

The declaration style keeps everything defined in a local scope and then only exposes window.numeric as a last resort.

I've done a build, and all unit tests pass

In order to get around the difficulty of the functions defined with the Function constructor, I had to wrap all of these constructions with a small internal function _fn() which simply does the following:

function _fn( fn ){
    fn.numeric = numeric;
    return fn;
}

so that the body of a function created with the Function constructor (which doesn't have access to the scope that defines numeric), will have access to numeric via

var numeric = arguments.callee.numeric;

I think this was the best way of getting around the scoping issues. But if anyone has a better way, I'm all ears.

Cheers!

@Pomax
Copy link

Pomax commented Apr 18, 2015

This is a pretty old PR, and does way more than the patch title claims. A separate PR just to expose the top level numeric in the proper way so that it will work in plain browser mode as well as when used as AMD or Commonjs module would be most excellent to have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants