2

if you have a simple javascript file foo.js like so:

function doSomething (){ console.log('done'); } module.exports = doSomething; 

if this file/module is required, it will get cached (any information about this online that you could point me to would be great).

so, in another JS file we have:

var foo1 = require('foo'); // yup 

and in yet another file we have:

var foo2 = require('foo'); // points to same cache as foo1 

but what happens with the cache when we call:

var foo3 = new foo2(); // doesn't point to same cache as foo2 and foo1? 

I assume a new copy of something is created, but what exactly happens beneath the surface? I am wondering this because I want to know how robust a particular singleton pattern is in JavaScript.

1
  • 1
    Why do you think calling a loaded function would affect module loader's cache? :) Commented Dec 30, 2014 at 21:20

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.