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(invalidIdentifier)) { throw new ReferenceError(varName + ": Invalid identifier"); } return varName.replace(/[^\w]+/g, ''); } function send(varName) { return eval(clean(varName)); } return { send: send }; })(); function logResultOrLogError(func) { try { console.log(func()); } catch (e) { console.log(e); } } logResultOrLogError(function () { return obj.send('private'); }); logResultOrLogError(function () { return obj.send('blah'); }); logResultOrLogError(function () { return obj.send('alert("I am teh hax0rz")'); }); 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 in production code, just thought it was a nice idea :) So, what do you think? Cheers -- 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/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com