Created
January 4, 2010 14:36
-
-
Save subtleGradient/268543 to your computer and use it in GitHub Desktop.
CommonJS: Extending native prototypes from a module
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
require('footools').setup(Array, Boolean, Function, Number, RegExp, String); | |
"bar".foo(); // no Fail |
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
require('footools').setup(Array, Boolean, Function, Number, RegExp, String); | |
"bar".foo(); // no Fail |
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
// 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); | |
}; |
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
<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