Skip to content

Instantly share code, notes, and snippets.

@reggi
Created June 22, 2018 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reggi/1d4bdb53dc6211f58b56444e4a374603 to your computer and use it in GitHub Desktop.
Save reggi/1d4bdb53dc6211f58b56444e4a374603 to your computer and use it in GitHub Desktop.
The idea is simple, all variables defined within a function are always returned and accessable outside of the function, no variables are ever "locked" inside a function.
* If it's called within a Prophesy the values declared within all Prophesys are retained in a shallow object.
* If it's called outside a Prophesy only the return property is returned.
* If there is no return property all properties are returned.
* Everything is maintained in a plain "Object". `{}`
```javascript
const add = new Prophesy((a, b) => [
() => ({a, b}),
() => ({return: a + b})
])
```
```javascript
const example = new Prophesy(() => [
() => ({a: 1, b: 2}),
({a, b}) => ({addResultAlpha: add(a, b)})
({a, b}) => ({addResultBeta: add(addResultAlpha, b)})
])
```
```json
{
"a": 1,
"b": 2,
"addResultAlpha": 3,
"addResultAlpha.a": 1,
"addResultAlpha.b": 2,
"addResultBeta": 5,
"addResultBeta.a": 3,
"addResultBeta".b: 2
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment