Created
June 6, 2011 15:55
-
-
Save jfsiii/1010516 to your computer and use it in GitHub Desktop.
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(){ | |
function Klass(id){ this._id = id; } | |
Klass.prototype.id = function(){ console.log(this._id); } | |
expose('Klass', Klass); | |
/*! | |
* expose.js | |
* | |
* @author Oleg Slobodskoi | |
* @website https://github.com/kof/expose.js | |
* @licence Dual licensed under the MIT or GPL Version 2 licenses. | |
*/ | |
function expose(namespace, api) { | |
var env = {}; | |
if (typeof namespace !== 'string') { | |
api = namespace; | |
namespace = null; | |
} | |
// the global api of any environment | |
// thanks to Nicholas C. Zakas | |
// http://www.nczonline.net/blog/2008/04/20/get-the-javascript-global/ | |
env.global = (function(){ | |
return this; | |
}).call(null); | |
// expose passed api as exports | |
env.exports = api || {}; | |
// commonjs | |
if (typeof module !== 'undefined' && | |
typeof exports !== 'undefined' && | |
module.exports) { | |
env.commonjs = true; | |
env.module = module; | |
module.exports = exports = env.exports; | |
} | |
// browser only | |
if (typeof window !== 'undefined') { | |
env.browser = true; | |
// we are not in amd wrapper | |
if (!env.commonjs && namespace && env.exports) { | |
env.global[namespace] = env.exports; | |
} | |
} | |
return env; | |
} | |
})(); |
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
> var Klass = require('./js/boilerplate.js') | |
> var foo = new Klass('foo') | |
> foo.id() | |
foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment