Skip to content

Commit

Permalink
Style conformance.
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascrockford committed Feb 23, 2011
1 parent 633fe5a commit ad6079c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
24 changes: 14 additions & 10 deletions cycle.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// cycle.js
// 2011-01-18
// 2011-02-23

/*jslint forin: true, evil: true */
/*jslint evil: true, regexp: false */

/*members $ref, apply, call, decycle, hasOwnProperty, length, prototype, push,
retrocycle, stringify, test, toString
*/

if (typeof JSON.decycle !== 'function') {
JSON.decycle = function decycle(object) {
"use strict";

// Make a deep copy of an object or array, assuring that there is at most
// one instance of each object or array in the resulting structure. The
Expand Down Expand Up @@ -74,7 +75,7 @@ if (typeof JSON.decycle !== 'function') {

nu = {};
for (name in value) {
if (Object.hasOwnProperty.call(value, name)) {
if (Object.prototype.hasOwnProperty.call(value, name)) {
nu[name] = derez(value[name],
path + '[' + JSON.stringify(name) + ']');
}
Expand All @@ -93,6 +94,7 @@ if (typeof JSON.decycle !== 'function') {

if (typeof JSON.retrocycle !== 'function') {
JSON.retrocycle = function retrocycle($) {
"use strict";

// Restore an object that was reduced by decycle. Members whose values are
// objects of the form
Expand Down Expand Up @@ -140,13 +142,15 @@ if (typeof JSON.retrocycle !== 'function') {
}
} else {
for (name in value) {
item = value[name];
if (item && typeof item === 'object') {
path = item.$ref;
if (typeof path === 'string' && px.test(path)) {
value[name] = eval(path);
} else {
rez(item);
if (typeof value[name] === 'object') {
item = value[name];
if (item) {
path = item.$ref;
if (typeof path === 'string' && px.test(path)) {
value[name] = eval(path);
} else {
rez(item);
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions json.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
json.js
2011-01-18
2011-02-23
Public Domain
Expand Down Expand Up @@ -365,7 +365,7 @@ if (!JSON) {
// Otherwise, iterate through all of the keys in the object.

for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
Expand Down Expand Up @@ -450,7 +450,7 @@ if (!JSON) {
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
Expand Down
10 changes: 5 additions & 5 deletions json2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
http://www.JSON.org/json2.js
2011-01-18
2011-02-23
Public Domain.
Expand Down Expand Up @@ -315,8 +315,8 @@ if (!JSON) {
if (rep && typeof rep === 'object') {
length = rep.length;
for (i = 0; i < length; i += 1) {
k = rep[i];
if (typeof k === 'string') {
if (typeof rep[i] === 'string') {
k = rep[i];
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
Expand All @@ -328,7 +328,7 @@ if (!JSON) {
// Otherwise, iterate through all of the keys in the object.

for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = str(k, value);
if (v) {
partial.push(quote(k) + (gap ? ': ' : ':') + v);
Expand Down Expand Up @@ -413,7 +413,7 @@ if (!JSON) {
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
Expand Down
7 changes: 4 additions & 3 deletions json_parse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
http://www.JSON.org/json_parse.js
2011-01-18
2011-02-23
Public Domain.
Expand Down Expand Up @@ -47,10 +47,11 @@
*/

/*members "", "\"", "\/", "\\", at, b, call, charAt, f, fromCharCode,
hasOwnProperty, message, n, name, push, r, t, text
hasOwnProperty, message, n, name, prototype, push, r, t, text
*/

var json_parse = (function () {
"use strict";

// This is a function that can parse a JSON text, producing a JavaScript
// data structure. It is a simple, recursive descent parser. It does not use
Expand Down Expand Up @@ -329,7 +330,7 @@ var json_parse = (function () {
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
Expand Down
9 changes: 5 additions & 4 deletions json_parse_state.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
http://www.JSON.org/json_parse_state.js
2011-01-18
2011-02-23
Public Domain.
Expand Down Expand Up @@ -51,11 +51,12 @@
/*members "", "\"", ",", "\/", ":", "[", "\\", "]", acomma, avalue, b,
call, colon, container, exec, f, false, firstavalue, firstokey,
fromCharCode, go, hasOwnProperty, key, length, n, null, ocomma, okey,
ovalue, pop, push, r, replace, slice, state, t, test, true, value, "{",
"}"
ovalue, pop, prototype, push, r, replace, slice, state, t, test, true,
value, "{", "}"
*/

var json_parse = (function () {
"use strict";

// This function creates a JSON parse function that uses a state machine rather
// than the dangerous eval function to parse a JSON text.
Expand Down Expand Up @@ -380,7 +381,7 @@ var json_parse = (function () {
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
if (Object.prototype.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
Expand Down

0 comments on commit ad6079c

Please sign in to comment.