Skip to content

Instantly share code, notes, and snippets.

@SergSlon
Created April 28, 2015 08:45
Show Gist options
  • Select an option

  • Save SergSlon/8e25c99aee163d7eb197 to your computer and use it in GitHub Desktop.

Select an option

Save SergSlon/8e25c99aee163d7eb197 to your computer and use it in GitHub Desktop.
Создание модуля JS
(function(root, factory) {
// это для загрузчика модуля АМД
if (typeof define === 'function' && define.amd) { // то есть, если можем дотянуться до define с amd,
define(['underscore', 'jquery', 'exports'], function(_, $, exports) { // то им модуль и создадим
// а вдруг кто-то ждет бэкбон еще и в глобальном объекте
root.Backbone = factory(root, exports, _, $);
});
// это для Node, где jQuery не нужен
} else if (typeof exports !== 'undefined') {
var _ = require('underscore');
factory(root, exports, _);
// это для браузера
} else {
root.Backbone = factory(root, {}, root._, (root.jQuery || root.Zepto || root.ender || root.$));
}
}(this, function(root, Backbone, _, $) { }));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment