Skip to content

Instantly share code, notes, and snippets.

@damien
Created March 19, 2012 17:00
Show Gist options
  • Select an option

  • Save damien/2119305 to your computer and use it in GitHub Desktop.

Select an option

Save damien/2119305 to your computer and use it in GitHub Desktop.
A simple version class
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