Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Requirejs, issue in loading the library underscore

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
});
like image 294
Lorraine Bernard Avatar asked May 31 '12 09:05

Lorraine Bernard


1 Answers

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

like image 85
ggozad Avatar answered Oct 11 '22 13:10

ggozad