It is easy, but why would it be legal?

Here's the third version of that prototype function to define a deep
value setting; this one supports changing the value of a preexisting
property.

Object.prototype.define = function(args, value) {
        if (typeof(args) != "string") { throw "Expected a String"; }

        args = args.split(".");

        var i = null,
            l = args.length,
            p = this;

        for (i = 0; i < l; i++) {
                (p[args[i]] === undefined) ? p[args[i]] = ((i+1 < l) ? {} : 
((value !
== undefined) ? value : null))
                                           : ((i+1 >= l) ? ((value !== 
undefined) ?
p[args[i]] = value : p[args[i]] = null) : void(0));
                p = p[args[i]];
        }

        return this;
};

On Feb 16, 11:30 am, Jason Persampieri <[email protected]> wrote:
> On Feb 16, 6:39 am, Jason Mulligan <[email protected]>
> wrote:
>
> > that's not really valid, undefined is as valuable as null when
> > checking an object; just write a handler and drop it onto the array
> > prototype.
>
> But why would:
>
> if ( d.foo.bar == "yay" ) {
>     [stuff]
>
> }
>
> preclude
>
> if ( d.foo === undefined ) {
>     [stuff]
>
> }
>
> ?  Shouldn't that be easy for the compiler to distinguish?  Basically,
> if at any depth a key is undefined, then stop going deeper and the
> whole thing just evaluates to undefined.

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to