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: .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?
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/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?
Share Improve this question asked Feb 6, 2012 at 23:36 mowwwalkermowwwalker 17.4k30 gold badges108 silver badges165 bronze badges 1-
It looks like
/t.*/
creates a regex object and applies it to the string ins
, and then appends "h" to the front. I wouldn't know whether/t.*/(s)
syntax is valid though. – mathematical.coffee Commented Feb 7, 2012 at 1:33
1 Answer
Reset to default 13Was 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.