-
-
Save subtleGradient/271224 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<script src="mootools.js"></script> | |
<script> | |
Moo.apply(this); // For non-strict browsers | |
Moo.apply(window); // For strict browsers | |
</script> |
This file contains hidden or 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
// CommonJS | |
var Moo = require('mootools'); | |
Moo.apply(this); // For most CommonJS implementations | |
// For strict CommonJS implementations | |
Moo.apply({ | |
String:String | |
}); | |
var Class = Moo.Class; | |
// For exported sandboxed natives support | |
// without breaking scripts in a normal context | |
// you wouldn't be able to use literals without a *.from() wrapped around it | |
(function(context, Array, Date/*, etc…*/){ | |
var myArray = Array.from([1,2,3]); | |
var myString = String.from("abc"); | |
var MyClass = new this.Class({ | |
}); | |
}).apply(MooTools, MooTools.natives); | |
// MooTools.natives is an array of [context, Array, Date, etc…] | |
This file contains hidden or 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
// Wrap all of MooTools code in a function | |
/*<b support="CommonJS Modules namespace">*/var MooTools = function(exports){/*</b>*/ | |
// fallback exports to `this` so that it can be used as both: | |
// `MooTools.apply(context)` | |
// this is the only style that'll work in CommonJS since exports can't be a function | |
// `MooTools(context)` | |
// `MooTools()` | |
if (typeof exports == 'undefined') exports = this; | |
var context = exports; | |
// changed `this.Whatever = …` to `exports.Whatever = …` to be more explicit what is being exported | |
var Class = exports.Class = function(){}; | |
// All natives must have `exports` prepended for sandboxed scope support | |
context.String.prototype.foo = function(){ return "foo'd"; }; | |
// Return the exports object for namespaced use | |
return exports; | |
/*<b support="CommonJS Modules namespace">*/};/*</b>*/ | |
/*<b support="CommonJS Modules namespace">*/// Create the exports object unless it exists | |
if (typeof exports == 'undefined') exports = {}; | |
/*</b>*/ | |
/*<b support="CommonJS Modules">*/ | |
// Create an apply method that will work in CommonJS | |
// since exports can't be a function | |
exports.apply = function(context, args){ | |
return MooTools.apply(context); | |
}; | |
/*</b>*/ | |
/*<b support="namespace">*/ | |
// add all natives to exports | |
exports.Array = Array; | |
exports.Boolean = Boolean; | |
exports.Date = Date; | |
exports.Function = Function; | |
exports.Number = Number; | |
exports.Object = Object; | |
exports.RegExp = RegExp; | |
exports.String = String; | |
// add some host objects to exports | |
if (typeof Element != 'undefined') exports.Element = Element; | |
// extend exports itself with MooTools for namespaced use | |
exports.apply(MooTools); | |
/*</b>*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment