Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use global context in scope bootstrap

The intent is to allow the declaration of subsequent scope implementations
using the scope() function defined by scope-bootstrap.
  • Loading branch information...
commit 4d1f9624cf50a8f9fddba236cc5a526e7e9930c5 1 parent 79d3790
@eric-brechemier authored
Showing with 19 additions and 11 deletions.
  1. +7 −2 README.txt
  2. +12 −9 scope-bootstrap.js
View
9 README.txt
@@ -105,15 +105,20 @@ APPLICATION PROGRAMMING INTERFACE (API)
name - string, optional, name of the context property to set the value
that the code may return
- Note:
+ Notes:
The context may be, depending on the implementation, the global object or the
window object in browser environment, a shared singleton object, or a context
object created specifically for this code based on its name and needs.
+ Implementations of scope() may be stacked, started with scope-bootstrap.js:
+ each implementation should expect that a new "scope" may be defined in its
+ context; it may then call the new scope() before, after, or instead of its
+ own implementation depending on what's most relevant.
+
INCLUDED IMPLEMENTATIONS
scope-api.js - null implementation (does nothing) with inline documentation
- scope-bootstrap.js - static synchronous definition in single shared context
+ scope-bootstrap.js - static synchronous definition in global context
scope-amd.js - Asynchronous Module Definition [3]
scope-record.js - record the order of calls to code() using an implementation
loaded previously, e.g. to combine scripts for optimization
View
21 scope-bootstrap.js
@@ -1,25 +1,28 @@
-// Static synchronous definition in single shared context
+// Static synchronous definition in global context
// Implementation of scopeornot API
// https://github.com/eric-brechemier/scopeornot
/*
Function: scope(code,needs,name)
Run code immediately, without taking needs into account, and set the return
- value, if any, to a property with given name in the single shared context.
+ value, if any, to a property with given name in the global context.
Parameters:
- code - function(context), the code to run with the context as parameter
+ code - function(context), the code to run with the global context provided
+ as parameter
needs - array of strings, the names of the properties that this code would
- like to find in the context (for documentation purpose)
- name - string, optional, name of the context property to set the value
- that the code may return
+ like to find in the global context (for documentation purpose)
+ name - string, optional, name of the global context property to set the
+ value that the code may return
Note:
- The context is a shared singleton object in this implementation.
+ The global context is accessed using "this" when scope() is called. A
+ different context may be used if the scope() function is applied to another
+ object instead.
*/
var scope = (function(){
- // single shared context
- var context = {};
+ // global context
+ var context = this;
function scope(code,needs,name){
// call code synchronously, without taking needs into account
Please sign in to comment.
Something went wrong with that request. Please try again.