You can attach functions to an Object in JavaScript, but you cannot 
serialize/deserialize functions inside JavaScript Objects using JSON (at 
least not without extra meta-programming).  Functions are not one of the 
basic JSON types (Number, String, Boolean, Array, Object, null).

var a = {foo: function () {console.log('Hello');}};
JSON.stringify(a); // yields "{}"



On Wednesday, July 23, 2014 7:46:56 PM UTC-4, Rohit Harchandani wrote:
>
> Hi, I have just started playing around with node.js for a project. I 
> parsed a JSON object which had a javascript function and when I tried to 
> execute the function on the node.js server, I kept getting this error:
> ReferenceError: require is not defined
> I am sure i parsed the JSON object correctly to get the function, but not 
> sure how to run this function. 
> Thanks,
> Rohit
>
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/790a9c77-e929-4f57-bbe5-03f6def13068%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to