felixge / node-sandboxed-module

A sandboxed node.js module loader that lets you inject dependencies into your modules.
MIT License
342 stars 42 forks source link

[help needed] [discussion] [usage question] accessing module private methods #54

Closed hellboy81 closed 8 years ago

hellboy81 commented 8 years ago

Is there possible to access private method with sandboxed-module?

function myPrivateMethod() {
}

module.exports.init = function (...) {
  myPrivateMethod()
}

i.e:

domenic commented 8 years ago

There is not. I don't even know how you would do that in JavaScript.

hellboy81 commented 8 years ago

you would do that in JavaScript.

with rewire you can do it:

myMod = rewire('...')
myMod.__set__()
myMod.__get__()
domenic commented 8 years ago

Cool! Then I'd suggest using rewire.