6

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?

1 Answer 1

14

Function.toString is your friend.

Try:

map.toString();
Sign up to request clarification or add additional context in comments.

2 Comments

Not at all. Did you try it?
@SergeyBasharov Seem to work okay: jsfiddle.net/DZ8mp If it doesn't work for you, could you edit your question to explain exactly why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.