[Mapbender-dev] JSON revisited
Marc Jansen
jansen.marc at gmx.de
Thu Jan 18 11:24:26 EST 2007
Christoph Baudson (WhereGroup) schrieb:
>>> Because JSON overloads several JS datatypes, some conflicts emerge.
>>> For example, for (var attribute in object) suddenly doesn't work
>>> anymore because it has an additional attribute: the JSON functions :-)
>>
>> Is this the case? That's new to me... but the whole (actual) JSON
>> coding is new to me ;-)
>>
>> How often do we use
>> for ... in
>> though?
>
> The Json library adds function like "toJsonString" to data types like
> Array. So if you have associative arrays you can't use the
>
> for (var x in y)
>
> anymore, because the function is part of the array. Well, there aren't
> many situations where this construction is used in Mapbender, but
> maybe this advice is helpful to someone someday.
You're totally right on this. One possible workaround would be the
typeof-check:
// is untested and could
// surely be rewritten...
var isFunction = function (testvar) {
return (typeof(testvar) == 'function');
}
// your for ... in
for (var x in y) {
if (!isFunction(x)) {
// this is certainly not a function
}
}
-- Marc
More information about the Mapbender_dev
mailing list