You’re going to need to write a custom serializer similar to util.inspect
to get this. Be forewarned, though, there’s a reason functions aren’t displayed as their source by default: calling .toString()
on a function doesn’t include the closure environment for the function, so any lexically defined values that are in scope when the function was defined won’t be available later:
function mildCurry (a) {
return (b) => a + b;
}
const oneOff = { add2: mildCurry(2) }
// > oneOff.add2.toString()
// '(b) => a + b'
If you’re careful about how you define functions on objects (and also figure out whether you want to include prototype methods as part of this serialization) you can probably stay out of trouble, but this isn’t as generally useful as you might hope.
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CANkmNDecj0Mac9mXyh0-hpDdubMxZvT2Rdmp-4DK-KiOAZ-E-w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
You’re going to need to write a custom serializer similar to
util.inspect
to get this. Be forewarned, though, there’s a reason functions aren’t displayed as their source by default: calling.toString()
on a function doesn’t include the closure environment for the function, so any lexically defined values that are in scope when the function was defined won’t be available later:function mildCurry (a) { return (b) => a + b; } const oneOff = { add2: mildCurry(2) } // > oneOff.add2.toString() // '(b) => a + b'
If you’re careful about how you define functions on objects (and also figure out whether you want to include prototype methods as part of this serialization) you can probably stay out of trouble, but this isn’t as generally useful as you might hope.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CAHG3qKooLfAwJf-98fFQwWP8xLg_szZTcFm6giasLcStBG8OaQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/CANkmNDdYMzaMcw6wsOq9gynYCR-m48hRxcZ6iEDe7nS13H4c4g%40mail.gmail.com.