Created
January 12, 2012 01:07
-
-
Save yumitsu/1597823 to your computer and use it in GitHub Desktop.
This file contains 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 testObj = { | |
_version: '0.1', | |
setVersion: function(ver) { | |
this._version = ver; | |
return this; | |
}, | |
getVersion: function() { | |
return this._version; | |
}, | |
adjustVersion: function() { | |
var _ver, _obj, _ref; | |
_ver = this.getVersion().split('.'), | |
_obj = new Object({}), | |
_obj.major = typeof(arguments[0]) === "undefined" ? 0 : parseInt(arguments[0], 10), | |
_obj.minor = typeof(arguments[1]) === "undefined" ? 0 : parseInt(arguments[1], 10), | |
_obj._major = parseInt(_ver[0], 10), | |
_obj._minor = parseInt(_ver[1], 10); | |
new Array('major', 'minor').each(function(k) { | |
var i, _i; | |
i = _obj[k], _i = _obj['_' + k + '']; | |
if (i > 0 || i < 0 && _i >= 0 && (_i + i) >= 0) { | |
_i = _i + i; | |
} else if ((_i + i) < 0) { | |
_i = 0; | |
} | |
_obj['_' + k + ''] = _i; | |
}); | |
this.setVersion(''.concat(_obj._major).concat('.').concat(_obj._minor)); | |
delete _obj.major, | |
delete _obj.minor, | |
delete _obj._major, | |
delete _obj._minor; | |
return this; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment