[Prototype-core] Re: methodize parseInt parseFloat
Well, I'm using this one: Object.extend(String.prototype, { parseInt: parseInt.methodize(), parseFloat: parseFloat.methodize(), }); I thought this could be useful for someone else. I have been using methods for parseInt for a while. You simply call 'string'.to_i(); // by encapsulating this code in an anonymous function, we can avoid intrusion upon the global namespace (function() { var _ruby_methods = { to_i: function() { // helper function for parseInt return parseInt(_string, 10); } }; Object.extend(String.prototype, _ruby_methods); Object.extend(Number.prototype, _ruby_methods); })(); On Jan 28, 2:37�pm, artemy tregoubenko [EMAIL PROTECTED] wrote: Hello! What do you think about making parseInt parseFloat string methods too? -- arty (http://arty.name) -- arty ( http://arty.name ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: methodize parseInt parseFloat
On Jan 29, 3:41 am, artemy tregoubenko [EMAIL PROTECTED] wrote: Well, I'm using this one: Object.extend(String.prototype, { parseInt: parseInt.methodize(), parseFloat: parseFloat.methodize(), }); Clever. :-) In ECMAScript 4, parseInt and parseFloat are becoming static methods on Number, not on String (i.e., Number.parseInt(3)). I could more easily see adding String#toNumber, but it's not a must-have for me. What do others think? Cheers, Andrew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: methodize parseInt parseFloat
I'd like to see it make it into the framework but if I have to add it to extensions.js (my 'extra' methods for prototype) then its not the end of the world. On Jan 30, 2008 1:01 PM, Mislav Marohnić [EMAIL PROTECTED] wrote: On Jan 30, 2008 12:01 AM, Andrew Dupont [EMAIL PROTECTED] wrote: In ECMAScript 4, parseInt and parseFloat are becoming static methods on Number, not on String (i.e., Number.parseInt(3)). I could more easily see adding String#toNumber, but it's not a must-have for me. What do others think? I don't care very much either, that's why I think it's not needed. We have just witnessed how easy it is to add, then why don't leave it to the users who use parseInt/Float extensively? We only use it a couple of times within the framework. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: methodize parseInt parseFloat
On Jan 30, 2008 12:01 AM, Andrew Dupont [EMAIL PROTECTED] wrote: In ECMAScript 4, parseInt and parseFloat are becoming static methods on Number, not on String (i.e., Number.parseInt(3)). I could more easily see adding String#toNumber, but it's not a must-have for me. What do others think? I don't care very much either, that's why I think it's not needed. We have just witnessed how easy it is to add, then why don't leave it to the users who use parseInt/Float extensively? We only use it a couple of times within the framework. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: methodize parseInt parseFloat
This could be useful for parsing Element#getStyle results (to get rid of px) parseInt(element.getStyle('left')); // vs. element.getStyle('left').parseInt(); I don't think it's a significant difference though. Moreover, getStyle could return null and we all know what happens then. Speaking about getStyle and parseInt, we had to do a little trick in Prototype UI: Element.addMethods({ getNumStyle: function(element, style) { var value = parseInt($(element).getStyle(style)); return isNaN(value) ? null : value; } }) - kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---