Saturday 28 December 2019

When you define a function in NodeJS, which object is that function a member of?

In the browsers execution environment when you define a function, that function is a member of the windowobject. For example:function myFunc() { console.log( 'hello' ); } console.log( window.myFunc ); // valid In NodeJS, we don't have a window object, be we do have a global and a module object. However, when you define a function the same way in the NodeJS execution environment, this function is not part of global object or the module object.function myFunc() { console.log( 'hello' ); } console.log( global.myFunc ); // undefined console.log( module.myFunc ); // undefined So which object is myFunc a member of?

Submitted December 29, 2019 at 12:46AM by UnknownEssence

No comments:

Post a Comment