Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript regex shorthand?

I'm trying to enjoy some of the awesome javascript code golf submissions on anarchy code golf, but I keep seeing things like:

for(;s=readline();)print("h"+/t.*/(s))

...which was the JS winner for: http://golf.shinh.org/p.rb?ttp

I don't understand how that is correct javascript syntax, and I even tried resubmitting that, but it said object is not a function, which is something along the lines of what I would expect to happen.

Was this some kind of glitch or shorthand or something in an older javascript version?

like image 298
mowwwalker Avatar asked Feb 06 '12 23:02

mowwwalker


1 Answers

Was this some kind of glitch or shorthand or something in an older javascript version?

More or less, yes. According to that site's version info, it uses SpiderMonkey (Mozilla's JavaScript engine), which used to have the feature that regular-expression objects were callable; that is, that if re was a regular-expression object, then re(...) was equivalent to re.exec(...). That feature was removed in this change, a result of Bug 582717, and that site has since updated to a version that incorporates that removal.

like image 159
ruakh Avatar answered Oct 07 '22 13:10

ruakh