Skip to content

Instantly share code, notes, and snippets.

@jfsiii
Created June 6, 2011 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfsiii/1010516 to your computer and use it in GitHub Desktop.
Save jfsiii/1010516 to your computer and use it in GitHub Desktop.
(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;
}
})();
> 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