Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit769b88f

Browse files
committed
Add section about limitations
Closesjhnns#51jhnns#57
1 parent839e62b commit769b88f

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

‎README.md

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,39 @@ myModule.__with__({
133133
// port is still 3000 here because the promise hasn't been resolved yet
134134
```
135135

136+
###Limitations
137+
138+
**Variables inside functions**<br>
139+
Variables inside functions can not be changed by rewire. This is constrained by JavaScript and can't be circumvented by rewire.
140+
141+
```javascript
142+
// myModule.js
143+
(function () {
144+
// Can't be changed by rewire
145+
var someVariable;
146+
})()
147+
```
148+
149+
**Modules that export primitives**<br>
150+
rewire is not able to attach the`__set__`- and`__get__`-method if your module is just exporting a primitive. Rewiring does not work in this case.
151+
152+
```javascript
153+
// Will throw an error if it's loaded with rewire()
154+
module.exports=2;
155+
```
156+
157+
**Globals with invalid variable names**<br>
158+
rewire imports global variables into the local scope by prepending a list of`var` declarations:
159+
160+
```javascript
161+
var someGlobalVar=global.someGlobalVar;
162+
```
163+
164+
If`someGlobalVar` is not a valid variable name, rewire just ignores it.**In this case you're not able to override the global variable locally**.
165+
166+
**Special globals**<br>
167+
Please be aware that you can't rewire`eval()` or the global object itself.
168+
136169
###Caveats
137170

138171
**Difference to require()**<br>
@@ -155,18 +188,6 @@ myModule.__set__("console", {
155188

156189
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.
157190

158-
**Globals with invalid variable names**<br>
159-
rewire imports global variables into the local scope by prepending a list of`var` declarations:
160-
161-
```javascript
162-
var someGlobalVar=global.someGlobalVar;
163-
```
164-
165-
If`someGlobalVar` is not a valid variable name, rewire just ignores it.**In this case you're not able to override the global variable locally**.
166-
167-
**Special globals**<br>
168-
Please be aware that you can't rewire`eval()` or the global object itself.
169-
170191
<br />
171192

172193
API

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp