MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / serializer

Function serializer

lib/web/drags.js:21–40  ·  view source on GitHub ↗
(replacer, cycleReplacer)

Source from the content-addressed store, hash-verified

19 };
20
21var serializer = function (replacer, cycleReplacer) {
22 var stack = [], keys = [];
23
24 if (cycleReplacer == null) cycleReplacer = function (key, value) {
25 if (stack[0] === value) return "[Circular ~]";
26 return "[Circular ~." + keys.slice(0, stack.indexOf(value)).join(".") + "]"
27 };
28
29 return function (key, value) {
30 if (stack.length > 0) {
31 var thisPos = stack.indexOf(this);
32 ~thisPos ? stack.splice(thisPos + 1) : stack.push(this);
33 ~thisPos ? keys.splice(thisPos, Infinity, key) : keys.push(key);
34 if (~stack.indexOf(value)) value = cycleReplacer.call(this, key, value)
35 }
36 else stack.push(value);
37
38 return replacer == null ? value : replacer.call(this, key, value)
39 }
40}
41
42var newWidgetCanvas = function (w, h) {
43 var div = $('<div class="Field-remoteWidget" style="width:' + w + 'px; height:' + h + 'px;"><div class="Field-closebox">&#x2715;</div></div>')[0];

Callers 1

stringifyFunction · 0.85

Calls 3

indexOfMethod · 0.80
pushMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected