Created
October 22, 2012 08:07
-
-
Save zhuochun/3930248 to your computer and use it in GitHub Desktop.
Define JavaScript Frameworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
// Initial Setup | |
// ------------- | |
// Save a reference to the global object (`window` in the browser, `exports` | |
// on the server). | |
var root = this; | |
// Save the previous value of the `Backbone` variable, so that it can be | |
// restored later on, if `noConflict` is used. | |
var previousBackbone = root.Backbone; | |
// The top-level namespace. All public Backbone classes and modules will | |
// be attached to this. Exported for both CommonJS and the browser. | |
var Backbone; | |
if (typeof exports !== 'undefined') { | |
Backbone = exports; | |
} else { | |
Backbone = root.Backbone = {}; | |
} | |
// Current version of the library. Keep in sync with `package.json`. | |
Backbone.VERSION = '0.9.2'; | |
}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(window, undefined) { | |
// Map over jQuery in case of overwrite | |
var _jQuery = window.jQuery, | |
// Map over the $ in case of overwrite | |
_$ = window.$, | |
// Define a local copy of jQuery | |
jQuery = function( selector, context ) { | |
// The jQuery object is actually just the init constructor 'enhanced' | |
return new jQuery.fn.init( selector, context, rootjQuery ); | |
}; | |
jQuery.fn = jQuery.prototype = { | |
constructor: jQuery, | |
init: function() { | |
} | |
}; | |
// Expose jQuery to the global object | |
window.jQuery = window.$ = jQuery; | |
// Expose jQuery as an AMD module, but only for AMD loaders that | |
// understand the issues with loading multiple versions of jQuery | |
// in a page that all might call define(). The loader will indicate | |
// they have special allowances for multiple jQuery versions by | |
// specifying define.amd.jQuery = true. Register as a named module, | |
// since jQuery can be concatenated with other files that may use define, | |
// but not use a proper concatenation script that understands anonymous | |
// AMD modules. A named AMD is safest and most robust way to register. | |
// Lowercase jquery is used because AMD module names are derived from | |
// file names, and jQuery is normally delivered in a lowercase file name. | |
// Do this after creating the global so that if an AMD module wants to call | |
// noConflict to hide this version of jQuery, it will work. | |
if ( typeof define === "function" && define.amd && define.amd.jQuery ) { | |
define( "jquery", [], function () { return jQuery; } ); | |
} | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment