Top.Mail.Ru
? ?
Javascript's Journal
 
[Most Recent Entries] [Calendar View] [Friends View]

Thursday, January 11th, 2007

Time Event
7:17p
JavaScript support for s///e.

I wrote the below (cut) function for those who mourn JavaScript's lack of an equivalent to Perl's s///e.

Read more...Collapse )

So, I have a few questions:

  • Was this a good idea? Am I inappropriately trying to mold JavaScript in Perl's image? (I'm rather new to the Tao of JavaScript, as it were.)
  • Is this the right way to do it? I originally created a replaceEval function that operated like String.replace except for applying eval() a specified number of times (default 1), but I ended up scrapping that because the eval()s would get invoked in the scope of replaceEval's definition rather than in the scope of its invocation, preventing replacement-strings from using local variables (including local functions). I'm not sure if this is really the Right Way, though.
  • How inefficient is this? Obviously it involves applying a bunch of eval()s and String.replace()s, but I don't know exactly how intensive those are. Is this something to be concerned about? Is there a way to improve it?
  • Any other comments?

(BTW, if the above function looks useful to you, feel free to use it.)

<< Previous Day 2007/01/11
[Calendar]
Next Day >>
About LiveJournal.com
Image