You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
This can especially be a problem if the module is not idempotent[like mongoose models](https://github.com/jhnns/rewire/issues/27).
146
146
147
-
**Changing globals**<br>
148
-
Be careful, if you do something like this you'll change your globalconsole instance.
147
+
**Dot notation**<br>
148
+
Although it is possible to use dot notation when calling`__set__`, it is strongly discouraged in most cases. For instance, writing`myModule.__set__("console.log", fn)` is effectively the same as just writing`console.log = fn`. It would be better to write:
149
149
150
150
```javascript
151
-
myModule.__set__("console.log",function () {/* be quiet*/ });
151
+
myModule.__set__("console", {
152
+
log:function () {}
153
+
});
152
154
```
153
155
156
+
This replaces`console` just inside`myModule`. That is, because rewire is using`eval()` to turn the key expression into an assignment. Hence, calling`myModule.__set__("console.log", fn)` modifies the`log` function on the*global*`console` object.
157
+
154
158
**Globals with invalid variable names**<br>
155
159
rewire imports global variables into the local scope by prepending a list of`var` declarations:
156
160
@@ -166,7 +170,7 @@ Please be aware that you can't rewire `eval()` or the global object itself.
166
170
<br />
167
171
168
172
API
169
-
------
173
+
---
170
174
171
175
###rewire(filename: String): rewiredModule
172
176
@@ -190,16 +194,16 @@ Returns a function which - when being called - sets `obj`, executes the given `c