I built a small javascript library I need to use inside a BackboneJS project. My problem is, I have an issue to use the library. I think I did something wrong, when I'm trying to access it, I got an "undefined".
Some code below, I simplified it.
The library looks something like that - myLibrary.js:
(function() {
var myLibrary = this;
var initialize = function() {
console.log('initialize');
};
myLibrary.otherFunction = function() {
console.log('otherFunction');
};
return myLibrary;
})();
I putted my library in my requirejs config:
requirejs.config({
paths: {
jquery: "js/jquery"
myLibrary: "js/myLibrary"
},
shim: {
myLibrary: {
deps: ['jquery']
}
}
});
And I'm trying to use my library inside a BackboneJS view
define([
'jquery',
'backbone',
'myLibrary'
], function($, Backbone, myLibrary){
'use strict';
return Backbone.View.extend({
initialize: function() {
console.log(myLibrary);
//myLibrary is undefined here!
//I'd like to access myLibrary as an object
//to access my functions inside..
}
});
});
The library is loaded. I can see it in the Network tab of my developer bar.
If you have any idea what's wrong here?
Thanks.