couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eric casteleijn <eric.castele...@canonical.com>
Subject Re: view syntax for retrieving object without a field
Date Mon, 25 Jan 2010 16:51:05 GMT
> Let's provide you with a better alternative, you need only one view to handle
> all possible negations, you only need to specify on which negations you want
> to select, check it out!
>
> function (doc)
> {
>    var fields = new Array("name", "country");
>
>    for (idx in fields)
>    {
>      if (typeof eval("doc." + fields[idx]) == "undefined")
>      {
>        emit(fields[idx], null);
>      }
>    }
> }
>

I think it's perfectly safe in this case, but in general I would not 
encourage the use of eval, as it might trip up inexperienced developers 
into creating serious security issues in their applications.

Almost always you can solve the problem without eval, as I think is the 
case here, at the expense of a little more code. Unfortunately the proof 
is too large to fit in the margin. ;)


Mime
View raw message