Skip to content

Instantly share code, notes, and snippets.

@elvis501
Created March 12, 2020 18:06
Show Gist options
  • Select an option

  • Save elvis501/e68bf241d2941d5538088bf6ff04307f to your computer and use it in GitHub Desktop.

Select an option

Save elvis501/e68bf241d2941d5538088bf6ff04307f to your computer and use it in GitHub Desktop.
js Class Skeleton
(function (global) {
function SkelClass() {
// handle cases where "new" keyword wasn't used
if (!(this instanceof SkelClass)) {
return new SkelClass(arguments[0]);
}
// if no arguments, then nothing needs to be set
if (arguments.length === 0)
throw new Error('Missing Argument: You must pass a valid argument');
// this is the same in either scenario
this.somevariable = 0;
this.data = new Array(arguments[0]);
this.end = (this.size = arguments[0]) - 1;
// need to `return this` so `return SkelClass.apply` works
return this;
}
SkelClass.prototype = {
// properly set constructor
constructor : SkelClass,
/* methods */
functionName : function () {
return ;
}
};
if (typeof module === 'object' && module.exports) module.exports = SkelClass;
else global.SkelClass = SkelClass;
}(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment