Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
Created January 4, 2010 14:36
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save subtleGradient/268543 to your computer and use it in GitHub Desktop.
Save subtleGradient/268543 to your computer and use it in GitHub Desktop.
CommonJS: Extending native prototypes from a module
require('footools').setup(Array, Boolean, Function, Number, RegExp, String);
"bar".foo(); // no Fail
require('footools').setup(Array, Boolean, Function, Number, RegExp, String);
"bar".foo(); // no Fail
// Framework codez
function FooTools(){
this.String.prototype.foo = function(){ return "foo'd"; };
};
// Exporting
if (typeof exports == 'undefined') var exports = {};
exports.setup = function(Array, Boolean, Function, Number, RegExp, String){
var context = {
Array : Array,
Boolean : Boolean,
Function : Function,
Number : Number,
RegExp : RegExp,
String : String
};
FooTools.apply(context);
};
<script src="mod.js"></script>
<script>FooTools.apply(window);</script>
<script>"bar".foo(); /*no Fail*/</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment