diff --git a/src/backbonefire.js b/src/backbonefire.js index 0e208b5..491dd31 100644 --- a/src/backbonefire.js +++ b/src/backbonefire.js @@ -8,7 +8,7 @@ * License: MIT */ -(function(_, Backbone) { +var backbonefire = function(_, Backbone) { 'use strict'; Backbone.Firebase = {}; @@ -864,4 +864,27 @@ }); -})(window._, window.Backbone); +}; + +/*globals self, global, define, require, module */ +(function(backbonefire) { + 'use strict'; + var root = (typeof self == 'object' && self.self == self && self) || + (typeof global == 'object' && global.global == global && global); + + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['underscore', 'backbone'], function(_, Backbone) { + backbonefire(_, Backbone); + }); + } else if (typeof module === 'object' && module.exports) { + // Node/CommonJS + var _ = require('underscore'); + var Backbone = require('backbone'); + module.exports = backbonefire(_, Backbone); + } else { + // Browser globals + backbonefire(root._, root.Backbone); + } + +})(backbonefire);