Manage context with ease
Usage
var Context = ;var ctx = ; ctx; // console.log(ctx.get('value')) -> 'first version'ctx;ctx; // console.log(ctx.get('value')) -> 'second version'ctx;console; // -> 'first version'
API
new Context
Creates context object with methods:
Context.set(key, value)
Sets key for value in current context.
Context.get(key)
Gets value for key in current (or previous) context.
Context.snapshot(ctx)
Creates new Object and add it to ctx
prototype.
Context.restore(ctx)
Removes created Object from prototype chain of ctx.
Benchmark results
Benchmarking set -> snapshot -> get -> restore pattern:
Performance 1133011 op/s » Stack on array 668539 op/s » Stack on list 645 op/s » Stack on objectprototype