Created
March 12, 2020 18:06
-
-
Save elvis501/e68bf241d2941d5538088bf6ff04307f to your computer and use it in GitHub Desktop.
js Class Skeleton
This file contains hidden or 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 (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