So? That's nothing we haven't covered here. Personally I'd recommend:
String.prototype.toNumber = function() { return Number(this) };Actually I wouldn't recommend it, I'd recommend just using Number() or + without touching the prototype. On Fri, Feb 24, 2012 at 1:46 PM, Jorge <[email protected]> wrote: > On Feb 24, 2012, at 8:37 PM, Marcel Laverdet wrote: > > > You could extend String.prototype if you wanted to but it's probably one > of the less common ways to do this kind of thing. It has disadvantages like > portability, and it will ONLY works on strings. Using Number() or + on > something that's not a string (undefined, an object, a number) will work > fine, but your prototype idea will fail. If you did want to go this way I'd > recommend calling it `toNumber` to match the `toString` convention. > > String.prototype.toInt= function toInt () { return parseInt(this, 10) }; > "123 px".toInt() > 123 > -- > Jorge. > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines > You received this message because you are subscribed to the Google > Groups "nodejs" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
