7

I am using the require.version "2.0.0"
And I would like to get the underscore as a local variable:

Here's my code (1).

Why _ is undefined?
How can I get _ inside the function like a local variable


(1)

require.config({
    baseUrl: "./",
    paths: {
        'underscore': 'vendor/js/underscore-min'
    },
    shim: {
        'underscore': {
            exports: 'underscore'
        }
    }
});

require([
    'underscore'
 ], function(_) {
    "use strict";
    console.log(_); // undefined
});
3
  • 1
    Do you use the AMD fork of Underscore github.com/amdjs/underscore ? If not, that could explain your problem Commented May 31, 2012 at 14:55
  • @nikoshr thanks for your comment. I am not using the AMD fork of Underscore. anyway there is a way to fix this issue without using the AMD version? Commented May 31, 2012 at 14:58
  • @nikoshr Anyway if you look this article it seems that shim has been introduced to fix the not AMD plugin. Commented May 31, 2012 at 15:02

1 Answer 1

5

Well, just replace exports: 'underscore' by exports: '_'. This tells require to attach to _ the module. So the reference window._ will still work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.