Skip to content

Instantly share code, notes, and snippets.

@tracend
Created January 15, 2014 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tracend/8430847 to your computer and use it in GitHub Desktop.
Save tracend/8430847 to your computer and use it in GitHub Desktop.
_.toNumber() #underscore #mixin #cc
_.mixin({
// `toNumber` takes a value given as `numeric` parameter and tries to turn it into a number.
// If it is not possible it returns 0 (or other value given as `fallback`).
toNumber : function (numeric, fallback) {
return isNaN(numeric) ? (fallback || 0) : Number(numeric);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment