Could somebody explain this subtlety of Javascript to me?
This works fine:
$ curl -X POST -d '{"map":"x=123; function(doc) { emit(x,null); }"}'
http://127.0.0.1:5984/mailme/_temp_view
{"total_rows":2,"offset":0,"rows":[
{"id":"54829ded88644559e6c81a7f482c5800","key":123,"value":null},
{"id":"ebf1585feb2109429a0cd62528e8ab4b","key":123,"value":null}
]}
But this doesn't:
$ curl -X POST -d '{"map":"var x=123; function(doc) { emit(x,null); }"}'
http://127.0.0.1:5984/mailme/_temp_view
{"error":"compilation_error","reason":"expression does not eval to a function.
(var x=123; function(doc) { emit(x,null); })"}
The only difference is the addition of the word 'var'.
(The reason: I'm writing a map function which needs to use a precalculated
lookup table)
Thanks,
Brian.