On Sun, Aug 21, 2011 at 8:23 PM, Nick Morgan <[email protected]> wrote:

> That was an incomplete refactoring! I did have two regex literals,
> then I assigned the first to `invalidIdentifier`, but forgot to
> replace the second regex literal with `invalidIdentifier` :/
>
> But yes, you're right, I could've just done RegExp#replace once,
> rather than a match followed by a replace.


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?

(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]).

/L
[1] That also allows you to share functions through the prototype, instead
of making new function objects for each object instance, increasing the
memory footprint of objects significantly.

-- 
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]

Reply via email to