I am creating JavaScript functions for map/reduce operations on database server side. To have syntax highlighting and errors check I make it like this inside my text editor:
var map = function (doc, meta) {
emit([doc.type, doc.created], doc);
};
Then I need to somehow turn it into a string variable so that to add it as a view to Couchbase looking like this:
var map = "function (doc, meta) { emit([doc.type, doc.created], doc); };"
Is that possible to convert the source code to a string somehow?
Function.toString
is your friend.
Try:
map.toString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With