Skip to content

Commit

Permalink
no mess
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Crockford committed Feb 20, 2013
1 parent 43d7836 commit ff55d8d
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions cycle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
cycle.js
2012-08-19
2013-02-19
Public Domain.
Expand Down Expand Up @@ -50,20 +50,15 @@ if (typeof JSON.decycle !== 'function') {
name, // Property name
nu; // The new object or array

switch (typeof value) {
case 'object':
// typeof null === 'object', so go on if this value is really an object but not
// one of the weird builtin objects.

// typeof null === 'object', so get out if this value is not really an object.
// Also get out if it is a weird builtin object.

if (value === null ||
value instanceof Boolean ||
value instanceof Date ||
value instanceof Number ||
value instanceof RegExp ||
value instanceof String) {
return value;
}
if (typeof value === 'object' && value !== null &&
!(value instanceof Boolean) &&
!(value instanceof Date) &&
!(value instanceof Number) &&
!(value instanceof RegExp) &&
!(value instanceof String)) {

// If the value is an object or array, look to see if we have already
// encountered it. If so, return a $ref/path object. This is a hard way,
Expand Down Expand Up @@ -100,11 +95,8 @@ if (typeof JSON.decycle !== 'function') {
}
}
return nu;
case 'number':
case 'string':
case 'boolean':
return value;
}
return value;
}(object, '$'));
};
}
Expand Down

0 comments on commit ff55d8d

Please sign in to comment.