Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rewire.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Ewald <johannes.ewald@peerigon.com>2015-04-28 01:10:39 +0300
committerJohannes Ewald <johannes.ewald@peerigon.com>2015-04-28 01:10:39 +0300
commit769b88f09015ae9e418c70675816ff5fc59df248 (patch)
tree1363059567b063dc1dc0b926f09c495592e5e4fb /README.md
parent839e62b3842d075b23b71bf7c02a2bc9ca1e695a (diff)
Add section about limitations
Closes #51 #57
Diffstat (limited to 'README.md')
-rw-r--r--README.md45
1 files changed, 33 insertions, 12 deletions
diff --git a/README.md b/README.md
index c2669cc..2e1a89a 100644
--- a/README.md
+++ b/README.md
@@ -133,6 +133,39 @@ myModule.__with__({
// port is still 3000 here because the promise hasn't been resolved yet
```
+### Limitations
+
+**Variables inside functions**<br>
+Variables inside functions can not be changed by rewire. This is constrained by JavaScript and can't be circumvented by rewire.
+
+```javascript
+// myModule.js
+(function () {
+ // Can't be changed by rewire
+ var someVariable;
+})()
+```
+
+**Modules that export primitives**<br>
+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.
+
+```javascript
+// Will throw an error if it's loaded with rewire()
+module.exports = 2;
+```
+
+**Globals with invalid variable names**<br>
+rewire imports global variables into the local scope by prepending a list of `var` declarations:
+
+```javascript
+var someGlobalVar = global.someGlobalVar;
+```
+
+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**.
+
+**Special globals**<br>
+Please be aware that you can't rewire `eval()` or the global object itself.
+
### Caveats
**Difference to require()**<br>
@@ -155,18 +188,6 @@ myModule.__set__("console", {
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.
-**Globals with invalid variable names**<br>
-rewire imports global variables into the local scope by prepending a list of `var` declarations:
-
-```javascript
-var someGlobalVar = global.someGlobalVar;
-```
-
-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**.
-
-**Special globals**<br>
-Please be aware that you can't rewire `eval()` or the global object itself.
-
<br />
API