From: Thomas 'PointedEars' Lahn on
Garrett Smith wrote:

> Asen Bozhilov wrote:
>> eval(properties);
>>
>> Of course that is not solve the design problems. I will prefer to use
>> array which contain each property name. For example:
>>
>> deep(context, ['property1', 'property2', 'propertyN']);
>
> Does deep check own or prototype?

You want to re-read the thread and re-think your question.


PointedEars
--
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
-- Richard Cornford, cljs, <cife6q$253$1$8300dec7(a)news.demon.co.uk> (2004)
From: Scott Sauyet on
Matt Kruse wrote:
> On May 11, 2:45 pm, Asen Bozhilov <asen.bozhi...(a)gmail.com> wrote:
>> I will prefer to use
>> array which contain each property name. For example:
>> deep(context, ['property1', 'property2', 'propertyN']);
>
> How is that any better than joining the array with "." and passing a
> single string?!

It's more general, not necessarily better. But it does address the
issues Thomas raises, and allows for the generality I was suggesting.
If your simple cases are all you ever need, by all means use a simpler
strategy.

It also has the advantage that you can pass variables holding strings
without manual concatenation. The only thing I would do differently
than the above is that I would remove the array and deal with variable
arguments; this seems cleaner to me:

deep(context, 'property1', 'property2', 'propertyN');

This still does not get at the even more general solution I mentioned,
and which I tried to implement some time ago. But of course that
solution had the problem yours does with property names containing
periods or brackets. I used an escape syntax for those, and that's
where some of the clean API went up in smoke.

I will see if I still have a copy of that code at home. I'm curious
to see how much five-year-old code might make me shudder.

--
Scott
From: Asen Bozhilov on
Matt Kruse wrote:
> Asen Bozhilov wrote:


> > I will prefer to use
> > array which contain each property name. For example:
> > deep(context, ['property1', 'property2', 'propertyN']);
>
> How is that any better than joining the array with "." and passing a
> single string?!

At all you miss the point and wrote in arrogant way that reply. Could
you show an implementation which works with:

var obj = {
property : {
'.property.' : {
'[property]' : true
}
}
};

$prop(obj, 'property[.property.][[property]]');

I expect `true' instead of `undefined'. So when you show that
implementation we can again talk about the complex of the problem
which you try to solve.

From: Matt Kruse on
On May 11, 4:20 pm, Scott Sauyet <scott.sau...(a)gmail.com> wrote:
> this seems cleaner to me:
>     deep(context, 'property1', 'property2', 'propertyN');

Would it handle this:

deep(context, 'prop1[0]')

if 'context' has no property named 'prop1'?
And what if 'context' has a property named 'myarray[0]' which is an
array?

deep(context, 'myarray[0][0]')

?

Matt Kruse
From: Garrett Smith on
Matt Kruse wrote:
> On May 11, 2:45 pm, Asen Bozhilov <asen.bozhi...(a)gmail.com> wrote:
>> Square bracket notation allow to used returned result by expression,
>> and that result is not bound as Identifiers rules defined by ECMA-262.
>> With your strategy you would have problems. For example:
>> var obj = {};
>> obj['.prop.'] = true;
>> obj['[prop]'] = true;
>>
>> print(obj['.prop.']);
>> print(obj['[prop]'])
>>
>> Your strategy is too complex
>
> But why would you EVER do that? I'm not building this for idiots!
>

Host:
navigator.plugins["Shockwave Flash 2.0"]?

User defined:
myObject[ prop.toString() ] = val;

[...]
--
Garrett
comp.lang.javascript FAQ: http://jibbering.com/faq/