Style conformance.

This commit is contained in:
Douglas Crockford 2011-02-23 13:54:25 -08:00
parent 633fe5ae4b
commit ad6079cbd8
5 changed files with 31 additions and 25 deletions

View file

@ -1,7 +1,7 @@
// 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
@ -9,6 +9,7 @@
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
@ -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) + ']');
}
@ -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
@ -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);
}
}
}
}

View file

@ -1,6 +1,6 @@
/*
json.js
2011-01-18
2011-02-23
Public Domain
@ -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);
@ -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;

View file

@ -1,6 +1,6 @@
/*
http://www.JSON.org/json2.js
2011-01-18
2011-02-23
Public Domain.
@ -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);
@ -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);
@ -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;

View file

@ -1,6 +1,6 @@
/*
http://www.JSON.org/json_parse.js
2011-01-18
2011-02-23
Public Domain.
@ -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
@ -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;

View file

@ -1,6 +1,6 @@
/*
http://www.JSON.org/json_parse_state.js
2011-01-18
2011-02-23
Public Domain.
@ -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.
@ -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;