Created
March 19, 2012 17:00
-
-
Save damien/2119305 to your computer and use it in GitHub Desktop.
A simple version 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
| var Version = function (major, minor, patch) { | |
| this.major = major | |
| this.minor = minor | |
| this.patch = patch | |
| } | |
| Version.prototype.toString = function () { | |
| return [this.major, this.minor, this.patch].join(".") | |
| } | |
| Version.prototype.isValid = function () { | |
| var pass = true | |
| _.each([this.major, this.minor, this.patch], function (n) { | |
| // Pass if this chunk of the version is a number and is not NaN | |
| // Protip: comparing NaN to itself will return false. | |
| if (typeof(n) !== "number" || n !== n) { | |
| pass = false | |
| } | |
| }) | |
| return pass ? true : false; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment