I'm working on some Map / Reduce queries for MongoDB and am trying to do the following (in a nutshell).
m = function()
{
this.convert = function(val)
{
return val+1;
}
emit(convert(this.age), this.doesWearGlasses);
}
r = function(k, v)
{
count = 0;
for(var i = 0; i < v.length; i++)
{
count += v[i];
}
return count;
}
if(tuned)
{
m.convert = function(val)
{
return val;
}
}
/**
* Continue to running the M/R query
*/
It should be noted that I'm writing this as a Node.js application, but I assume most of the same principals apply to any JavaScript.
The issue is I don't think I can change it without creating an object, ala mTmp = new m();
, however I can't because emit()
(and everything else) isn't defined.
I tried using m.prototype.convert = function
, but this doesn't work. The value of m.toString()
doesn't change.