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

wrap code for CommonJS environments and AMD #5

Open
millermedeiros opened this issue Sep 9, 2011 · 0 comments
Open

wrap code for CommonJS environments and AMD #5

millermedeiros opened this issue Sep 9, 2011 · 0 comments

Comments

@millermedeiros
Copy link

avoid generating globals if not needed and help to easily share code between environments.

here is a sample of a wrapper that would run "everywhere":

(function(def){
    def('jlink', function(){

        //jlinq code should go here

        return jlinq;
    });
}(
    // wrapper to run code everywhere
    // based on http://bit.ly/c7U4h5
    typeof require === 'undefined'?
        //Browser (regular script tag)
        function(name, factory){
            this[name] = factory();
        } :
        ((typeof exports === 'undefined')?
            //AMD
            function(name, factory){
                define(name, [], factory);
            } :
            //CommonJS
            function(name, factory){
                module.exports = factory();
            }
        )
));

wrapping the code like this would make it work on node.js, and to be loaded properly by AMD loaders like RequireJS, Dojo (v1.6+), curl.js, etc..

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

No branches or pull requests

1 participant