Skip to content

Commit ff55d8d

Browse files
author
Douglas Crockford
committed
no mess
1 parent 43d7836 commit ff55d8d

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

cycle.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
cycle.js
3-
2012-08-19
3+
2013-02-19
44
55
Public Domain.
66
@@ -50,20 +50,15 @@ if (typeof JSON.decycle !== 'function') {
5050
name, // Property name
5151
nu; // The new object or array
5252

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

56-
// typeof null === 'object', so get out if this value is not really an object.
57-
// Also get out if it is a weird builtin object.
58-
59-
if (value === null ||
60-
value instanceof Boolean ||
61-
value instanceof Date ||
62-
value instanceof Number ||
63-
value instanceof RegExp ||
64-
value instanceof String) {
65-
return value;
66-
}
56+
if (typeof value === 'object' && value !== null &&
57+
!(value instanceof Boolean) &&
58+
!(value instanceof Date) &&
59+
!(value instanceof Number) &&
60+
!(value instanceof RegExp) &&
61+
!(value instanceof String)) {
6762

6863
// If the value is an object or array, look to see if we have already
6964
// encountered it. If so, return a $ref/path object. This is a hard way,
@@ -100,11 +95,8 @@ if (typeof JSON.decycle !== 'function') {
10095
}
10196
}
10297
return nu;
103-
case 'number':
104-
case 'string':
105-
case 'boolean':
106-
return value;
10798
}
99+
return value;
108100
}(object, '$'));
109101
};
110102
}

0 commit comments

Comments
 (0)