Created
March 23, 2015 01:57
-
-
Save AdamCaviness/b2fee8f1f6ccdb6280ab to your computer and use it in GitHub Desktop.
Douglas Crockford class
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
/*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