Skip to content

Instantly share code, notes, and snippets.

@edwardhotchkiss
Created August 17, 2013 04:06
Show Gist options
  • Save edwardhotchkiss/6255203 to your computer and use it in GitHub Desktop.
Save edwardhotchkiss/6255203 to your computer and use it in GitHub Desktop.
// compatible with (if available) RequireJS/AMD
(function(root) {
'use strict';
/* ---- private ---- */
/**
* @private _hasConsole
*/
var _hasConsole = (typeof(window.console) === 'object');
/**
* @private _log
* @description check for console, log
* @param {String} args console.log arguments
*/
function _log(msg) {
if (!_hasConsole) {
return;
}
var log, args;
args = Array.prototype.slice.call(arguments);
log = Function.prototype.bind.call(console.log, console);
log.apply(console, args);
}
/**
* @constructor Skeleton
*/
var Skeleton = function Skeleton(name) {
params = params || {};
this.name = params.name || 'default';
this.initialize();
}
/* ---- instance prototypes ---- */
Skeleton.prototype = {
/**
* @method initialize
* @description called on instantiation
*/
initialize: function() {
_log('this skeleton\'s name is "%s"', this.name);
}
};
/**
* @description check if RequireJS/AMD is available,
* and `define` it within RequireJS. Otherwise, use the
* standard window.<MyModule> approach
*/
if (typeof(require) === 'function' && typeof(define) === 'function' && define.amd) {
define('skeleton', [], function() {
return Skeleton;
});
} else {
root.Skeleton = Skeleton;
}
// "root"
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment