Re: [JSMentors] Accessing private vars in the revealing module pattern

2011-08-22 Thread Nick Morgan
On 22 August 2011 17:57, Angus Croll wrote: > Nick, more power to you for experimenting with eval. Blanket rejection of > "bad practices" makes the language go stale. Understanding the risks and > using a feature judiciously is a better approach (I'm sure there was a time > when folks shook their

Re: [JSMentors] Accessing private vars in the revealing module pattern

2011-08-22 Thread Nick Morgan
On 22 August 2011 08:11, Lasse Reichstein 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

Re: [JSMentors] Accessing private vars in the revealing module pattern

2011-08-22 Thread Lasse Reichstein
On Sun, Aug 21, 2011 at 8:23 PM, Nick Morgan 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

Re: [JSMentors] Accessing private vars in the revealing module pattern

2011-08-21 Thread Nick Morgan
On 21 August 2011 18:30, Danilo Celic wrote: > Nick, > > I think that you can get away with only using the RegExp once (especially > since the code you sent set the RegExp into a variable, uses that once, and > then you use another RegExp literal in your return statement): That was an incomplete

re: [JSMentors] Accessing private vars in the revealing module pattern

2011-08-21 Thread Danilo Celic
t; To: jsmentors@googlegroups.com > Subject: [JSMentors] Accessing private vars in the revealing module pattern > > Hi guys > > Thought I'd share a little toy I just made, to see what you thought: > > http://jsfiddle.net/skilldrick/EjHWT/1/ > > var obj = (func

Re: [JSMentors] Accessing private vars in the revealing module pattern

2011-08-21 Thread Nick Morgan
On 21 August 2011 00:56, Christian C. Salvadó wrote: > > I agree with Peter, I'd expose only things I really want to. Personally, I > always try to avoid `eval`, IMHO avoiding `eval` is not just about the risks > of code evaluation, `eval` inhibits a lot of optimizations, for example, in > your co

Re: [JSMentors] Accessing private vars in the revealing module pattern

2011-08-20 Thread Christian C . Salvadó
On Sat, Aug 20, 2011 at 1:22 PM, Nick Morgan wrote: > On 20 August 2011 20:10, Peter van der Zee wrote: > > > Personally I'd never use a construct like this. Just expose private > > variables as you go. Using eval is dangerous, especially because I > > don't quite see the point of the regex. I m

Re: [JSMentors] Accessing private vars in the revealing module pattern

2011-08-20 Thread Nick Morgan
On 20 August 2011 20:10, Peter van der Zee wrote: > Personally I'd never use a construct like this. Just expose private > variables as you go. Using eval is dangerous, especially because I > don't quite see the point of the regex. I mean, what is clean() trying > to do? `alert('foo');` is going t

Re: [JSMentors] Accessing private vars in the revealing module pattern

2011-08-20 Thread Peter van der Zee
On Sat, Aug 20, 2011 at 8:22 PM, Nick Morgan wrote: > Hi guys > > Thought I'd share a little toy I just made, to see what you thought: > ... > It gives you access to the value of private vars via a safe eval. > Thought it might come in useful for testing occasionally. I'm not > suggesting using it

[JSMentors] Accessing private vars in the revealing module pattern

2011-08-20 Thread Nick Morgan
Hi guys Thought I'd share a little toy I just made, to see what you thought: http://jsfiddle.net/skilldrick/EjHWT/1/ var obj = (function () { var private = 5; var private2 = 10; function clean(varName) { var invalidIdentifier = /[^\w]+/g; if (varName.match(invalidIde