Skip to content

Instantly share code, notes, and snippets.

@AdamCaviness
Created March 23, 2015 01:57
Show Gist options
  • Save AdamCaviness/b2fee8f1f6ccdb6280ab to your computer and use it in GitHub Desktop.
Save AdamCaviness/b2fee8f1f6ccdb6280ab to your computer and use it in GitHub Desktop.
Douglas Crockford class
/*jslint node: true*/
'use strict';
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
};
function Parenizor(value) {
this.setValue(value);
}
Parenizor.method('setValue', function (value) {
this.value = value;
return this;
});
Parenizor.method('getValue', function () {
return this.value;
});
Parenizor.method('toString', function () {
return '(' + this.getValue() + ')';
});
var myParenizor = new Parenizor(0);
console.log(myParenizor.toString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment