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

Commit ed557dd

Browse files
sandbox pattern
1 parent 2f6eef0 commit ed557dd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎05-object-creation.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,25 @@ Person.prototype = (function(){
122122
1. globals can be passed in parameters to the immediate function
123123
* a module can create a constructor as well
124124
* if you return the constructor function instead of an object
125+
126+
## sandbox pattern
127+
128+
* addresses some namespace drawbacks: single global var, long dotted names
129+
130+
```js
131+
new SandBox('dependencies', 'here', function(box){
132+
// your code here
133+
});
134+
```
135+
136+
* you have a single global constructor
137+
* passed in callback function is you isolated environment
138+
* you initiate multiple Sandbox object and even nest them
139+
* you can name the constructor appropriately (instead of Sandbox)
140+
141+
## implementing the sandbox pattern
142+
143+
* as the Sandbox function is an object we can add a modules (object) property to it
144+
* add required modules to ```this```
145+
* then call callback with ```this```
146+
* the callback is the users sandbox and get populated with the requested functionality

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /