Published on

RAMSON, part 2


This post is the second part of the RAMSON series. Make sure you've read RAMSON, part 1.

As dicussed before, RAMSON is a JSON schema that serializes and deserializes JS/ECMAScript objects precisely as they were in memory.

For example, consider the following Javascript code:

var state = { foo: 1 };
var counter = 0;
function next_val() {
  counter = counter + 1;
  return counter;
var root = { state: state, next_val: next_val };

Let's focus on how to serialize the next_val function. A Javascript function is comprised of its source code, along with its scope.

Scope is the collection of variables defined in a function, along with a reference to its enclosing scope, the scope of the function's parent function scope. The enclosing scope is referenced even if the parent function has returned. A top-level function's enclosing scope is the of its module.

Assume we could access each function's scope, through a function's $$scope property. To properly chain enclosing scopes, we could utilize prototype.

So in the aforementioned example,

  • next_val.$$scope would be empty, since next_val doesn't define any variables,
  • next_val.$$scope.prototype would contain counter, and state, and
  • next_val.$$scope.prototype.prototype would be undefined.