On 22 August 2011 08:11, Lasse Reichstein <[email protected]> wrote: >
> If I read it correctly, you first check if the input contains any > non-word-character, and if so, throw an exception. > If you didn't throw, you then remove all non-word-characters - but you just > checked that there wasn't any, so the replace call is always a no-op? Yes, I noticed that. I left it in as a kind of belt-and-braces thing - it's a bit paranoid but I think a bit of paranoia's useful when using eval :) > (Now, personally, I dislike the use of scoped variables as "object private > fields". Stop putting lipstick on a pig, and just accept that Javascript > isn't safe and make the object property a property of the object[1]). I can't agree with this. JavaScript is a very simple language with some powerful concepts (proper functions and closures). It's up to the programmer to make use of those concepts in a way that works for them, and improves their programs. Just because the language doesn't hand you private variables on a plate, doesn't mean you shouldn't use them. I prefer to think for myself, and use the language in the way I'd like to use it (which includes private members). I don't think that's "putting lipstick on a pig". I can make JavaScript as safe as I want it to be. I'm fully aware that functions aren't shared this way, and if I get to a point with something where that looks like it's causing problems, then I'll refactor to use straight objects with prototypes. But changing the way you use the language because of memory use is just premature optimisation. -- Nick Morgan http://skilldrick.co.uk @skilldrick Save our in-boxes! http://emailcharter.org -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/[email protected]/ To search via a non-Google archive, visit here: http://www.mail-archive.com/[email protected]/ To unsubscribe from this group, send email to [email protected]
