Say I have a constructor that I want to modify the prototype of in accordance with locale (toString). Is there a way to re-execute the require statement to return new constructor instances that I can then mutate, and have multiple locale environments?
function createEnvironment(locale) {
var instance = rerequire('./instance');
instance.toString = localeToString[locale];
return instance;
}
This would have to recursively rerequire all the modules that instance required.
The context for needing to do this is a document-like project, where different documents have different locales. I could pass a locale instance into each instance object, but there are five other similar locale-dependent instances that would also need that instance, so that would just be a mess.
Edit:
Use rewire to accomplish this!