From: David Mark on
Matt Kruse wrote:
> On May 15, 10:45 am, Thomas 'PointedEars' Lahn <PointedE...(a)web.de>
> wrote:
>> No, I am saying that such a property-accessing function should allow access
>> to all properties.
>
> Your quest for completeness is cute, but ultimately futile.
>

[snip a heap of blithering]

I suppose you still use jQuery as well. :)

http://www.urbandictionary.com/define.php?term=pseudo-intellectual
From: Matt Kruse on
On May 17, 9:51 am, David Mark <dmark.cins...(a)gmail.com> wrote:
> [snip a heap of blithering]
> I suppose you still use jQuery as well.  :)
> http://www.urbandictionary.com/define.php?term=pseudo-intellectual

It's good to see that you are still here trolling with ad-hominem
attacks and spewing your same old tired mantra, David. But seriously,
isn't it time to grow up, move on, and discuss ideas instead of
attacking people?

Matt Kruse
From: Scott Sauyet on
David Mark wrote:
> http://www.urbandictionary.com/define.php?term=pseudo-intellectual

http://www.urbandictionary.com/define.php?term=troll
From: Scott Sauyet on
Matt Kruse wrote:
> Thomas 'PointedEars' Lahn wrote:

>> No, I am saying that such a property-accessing function should allow access
>> to all properties.
>
> Your quest for completeness is cute, but ultimately futile.

Nice to hear you back in this conversation! :-)


> A string delimited with '.' works in probably at least 99% of the
> cases in which I wish to use it, and probably the same for most
> people. Solving for the remaining <1% of cases requires a syntax that
> is less concise and convenient, and more prone to error (matching up
> quotes, etc).
>
> There is simply no compelling need to solve for the general case. I
> realize this probably bugs you to the core, but that is your personal
> problem.

I suggested a generalization in a different direction, and wonder if
you find that one any more interesting:

fetch("obj1.prop1.prop2[objA.propA.propB].prop3");

where both "obj1" and "objA" are assumed to be defined in the current
context, although the code should handle the case where they're not,
and objA.propA.propB contains the name of some property of
obj1.prop1.prop2, although again the code should handle things
appropriately when that's not true.

Because of this generalization, I find it easier to move the initial
object into the String and supply just a single string parameter.
Obviously I could add an optional delimiter parameter too if needed.

Would you find this useful?


> Pros:
>  - Simple, concise syntax
>  - Works for the vast majority of common cases
>  - Handles arrays[0], methods(), nested arrays[0][0], and even
> property names with empty brackets[]

And I think you could extend it relatively easily to handle property
names with content in the brackets as long as you were willing to risk
a possible ambiguity in

var objA = {
"propA": {
"propB": "myVal"
//, ...
} //, ...
};
var obj1 = {
"prop1": {
"prop2" : {
"myVal": {
"prop3": "final result"
//, ...
}
"objA.propA.propB": {
"prop3": "incorrect result"
//, ...
} //, ...
} // , ...
} //, ...
};

var result = fetch("obj1.prop1.prop2[objA.propA.propB].prop3");

> Cons:
>  - Fails for property names containing the delimiter
>  - String splitting is slightly less efficient than passing multiple
> args
>
> I'm perfectly happy with that balance, while still being interested in
> and seeing the benefits of solving the more general case.

I'm curious too, but would probably still use a simpler solution
unless my requirements started getting more complex.

--
Scott

From: Stefan Weiss on
On 17/05/10 15:12, Scott Sauyet wrote:
> $prop(obj, "foo.bar.baz")
>
> vs.
>
> $prop(obj, ["foo", "bar", "baz"]);
>
> Even in those rare cases where a delimiter is needed, I would argue
> that the first is simpler to read and understand that the latter. And
> mine went one step further, eliminating the first parameter, so it
> looked just like
>
> fetch("obj.foo.bar.baz");

How can that work unless obj is global?

[and unless $prop() is defined inside the scope where you call it, but
that would be silly]


--
stefan