Skip to content

jruchaud/scope-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

scope-proxy

Create scope for script tag with a proxy. Usefull to avoid the global variable and share variable in same scope.

Installation

npm install git://github.com/jruchaud/scope-proxy.git

<script type="application/javascript" src="/node_modules/scope-proxy/scope-proxy.js"></script>

Usage

Create the scope

<script>
    $scope = new ScopeProxy(window);
</script>

Describe the scope when you include your js

<script data-scope="kernel" type="application/javascript" src="kernel.js"></script>
<script data-scope="mod" type="application/javascript" src="mod.js"></script>
<script data-scope="mod" type="application/javascript" src="service.js"></script>

Share variable/object in same scope

  • In mod.js

$scope.value = "value";

  • You can use it in service.js like:

$scope.value -> "value"

  • However you cannot access in kernel.js

$scope.value -> undefined

  • Otherwise you can use exportScope:
$scope.exportScope(MyClass)
$scope.exportScope(new MyClass(), "myClass");

Share variable/object from other module

  • In kernel.js

$scope.value = "value";

  • You can use it in service.js like:
var kernel = $scope.importScope("kernel");
kernel.value -> "value"

About

Create scope for script tag with a proxy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published