https://github.com/yornaath/scope.js
Useless library for creating new scopes and preventing global leakage
https://github.com/yornaath/scope.js
Last synced: 7 months ago
JSON representation
Useless library for creating new scopes and preventing global leakage
- Host: GitHub
- URL: https://github.com/yornaath/scope.js
- Owner: yornaath
- Created: 2012-07-22T12:33:53.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2012-07-22T12:54:04.000Z (about 13 years ago)
- Last Synced: 2025-01-22T07:35:26.380Z (9 months ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Scope.js
A useless library for creating water proof function calls with no global leakage and its own scope. Totaly useless for production and just an experiment.
### Class: Scope
Constructs a new scope. It does not have access to the local scope but all globals.
#### Scope.eval( functionOrSourceString )
Evaluates the function or source string within the scope instances scope.
#### Scope.bind( functionOrSourceString )
Binds and returns a function that when executed will be called within the scope of the instance scope.
### Examples
```javascript
var scope = new Scope({
foo: 'bar',
num: 1
})scope.eval(function(){
return foo
})
// -> 'bar'scope.eval(function(){
var consideredGlobal = 'lol'
anotherGlobal = true
})typeof anotherGlobal === 'undefined'
// -> truescope.eval(function(){ return consideredGlobal })
// -> 'lol'scope.eval(function(){ return anotherGlobal })
// -> true```