Skip to content

Commit 4700593

Browse files
authored
docs: Add IIFE pattern for return statements in JS rules (#90)
Addresses issue #87 by documenting how to use return statements via the IIFE pattern.
1 parent e496e4c commit 4700593

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/guide/rule-engines/javascript.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ r.host === 'facebook.com' ? {deny_message: 'Social media blocked'} : true
6262
({allow: {max_tx_bytes: 1024}})
6363
```
6464

65+
## Using Return Statements
66+
67+
JavaScript rules don't allow naked `return` statements. To use returns, wrap your code in an IIFE:
68+
69+
```javascript
70+
(function() {
71+
if (r.host === 'github.com') {
72+
return true;
73+
}
74+
75+
if (r.host.match(/facebook|twitter/)) {
76+
return {deny_message: "Blocked"};
77+
}
78+
79+
return false;
80+
})();
81+
```
82+
6583
## Common Patterns
6684

6785
### Domain Allowlisting

0 commit comments

Comments
 (0)