[nodejs] module.exports and inner functions.

2015-11-03 Thread Joseph Arrieta
Hi guys,

I have a doubt if I have this a.js:

// a.js
module.exports = {
  someFunction: function() {
function innerFunction() {
  //code here
}
innerFunction();
  }
}

and this other one b.js:

// b.js
function outterFunction() {
//code here
}

module.exports = {
  someFunction: function() {
innerFunction();
  }
}

NodeJS files are cached whenever we require them, that's so far so good, 
now my question is does the innerFunction in file a.js its also cached? or 
everytime I call 
require('a.js').someFunction() the function innerFunction is redefined?

I would like to know about this because in case always the function is 
redefined I prefer to use the command pattern to define modules in node and 
then just attach what I just defined to module.exports like this, with this 
way all the functions will be cached by the mechanism of require (in case 
the function is always redefined in the file a.js):

// c.js
(function(){
  function outterFunction() {
// code here
  }

  function someFunction() {
outterFunction();
  }
})();

module.exports = {
  someFunction: someFunction
}

Thanks in advance guys.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/c2b5c9fd-beec-46c2-a63c-5800d7a5188f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [nodejs] module.exports and inner functions.

2015-11-03 Thread Aria Stewart

> On Nov 3, 2015, at 5:45 PM, Joseph Arrieta  wrote:
> 
> Hi guys,
> 
> I have a doubt if I have this a.js:
> 
> // a.js
> module.exports = {
>   someFunction: function() {
> function innerFunction() {
>   //code here
> }
> innerFunction();
>   }
> }
> 
> and this other one b.js:
> 
> // b.js
> function outterFunction() {
> //code here
> }
> 
> module.exports = {
>   someFunction: function() {
> innerFunction();
>   }
> }
> 
> NodeJS files are cached whenever we require them, that's so far so good, now 
> my question is does the innerFunction in file a.js its also cached? or 
> everytime I call 
> require('a.js').someFunction() the function innerFunction is redefined?

Yes and no.

It's a new function each time, though the parsing and compilation of it is 
cached, inside the runtime. If you were to return that function and compare it 
with another call, though, they'd be different.

This probably doesn't have any practical implications though that you could 
care about.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/8AC320B9-EFDD-44D8-BA6A-659B1CF5A238%40dinhe.net.
For more options, visit https://groups.google.com/d/optout.


smime.p7s
Description: S/MIME cryptographic signature


[nodejs] Re: Calculate statistics

2015-11-03 Thread Zlatko
That is really a too wide question.

The general answer is that you can (of course) use both. But which one is 
better?

It depends on so many things, your use cases, your current codebase, where 
is all the data being held, what kind of business inteligence and what kind 
of statistical information you're into. You'd have to get into much more 
detail to make a good choice. Perhaps you can even hire an independant 
consultant who can go with you and analyze your requirements and build a 
pros and cons for both choices and help you decide.

In any case, the question is really wide just set like that.


On Tuesday, November 3, 2015 at 1:11:42 AM UTC+1, Diego Mayorga wrote:
>
> Hi, i'm working with two databases, mongodb and influxdb, and I want to 
> generate statistical information for bussines inteligence. My question is 
> which of the two best supports statistical calculations?
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/5200b107-b5a4-49b0-a179-35cec78dd783%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.