N
None
Hi All
These code are part of Prototype. There are something that I don't
understand, would you please explain it for me?
.......
toJSON: function(object) {
var type = typeof object;
switch (type) {
case 'undefined':
case 'function':
case 'unknown': return;
case 'boolean': return object.toString();
}
if (object === null) return 'null';
if (object.toJSON) return object.toJSON();
--------------------------------------if toJSON is a function name,
it is a function that extends the Object
if object.toJSON is true and the return object.toJSON(), what is the
mean? It is like a loop.
if (Object.isElement(object)) return;
var results = [];
for (var property in object) {
var value = Object.toJSON(object[property]);
---------------------------------I think the value should be the value
of the property.But from the code above, I can not understand why
value can be the value of the property
if (!Object.isUndefined(value))
results.push(property.toJSON() + ': ' + value);
}
return '{' + results.join(', ') + '}';
},
Thanks,
These code are part of Prototype. There are something that I don't
understand, would you please explain it for me?
.......
toJSON: function(object) {
var type = typeof object;
switch (type) {
case 'undefined':
case 'function':
case 'unknown': return;
case 'boolean': return object.toString();
}
if (object === null) return 'null';
if (object.toJSON) return object.toJSON();
--------------------------------------if toJSON is a function name,
it is a function that extends the Object
if object.toJSON is true and the return object.toJSON(), what is the
mean? It is like a loop.
if (Object.isElement(object)) return;
var results = [];
for (var property in object) {
var value = Object.toJSON(object[property]);
---------------------------------I think the value should be the value
of the property.But from the code above, I can not understand why
value can be the value of the property
if (!Object.isUndefined(value))
results.push(property.toJSON() + ': ' + value);
}
return '{' + results.join(', ') + '}';
},
Thanks,