On Fri, Feb 4, 2011 at 11:47 AM, jemptymethod <jemptymet...@gmail.com>wrote:

> On Feb 4, 2:10 pm, jemptymethod <jemptymet...@gmail.com> wrote:
> > I want to delete a couple of object properties, but first save those
> > properties, then add them back after I'm done processing the object
> > *without* those properties.
> >
> > But I can't do the following, when I log the object to the console,
> > it's apparent the properties didn't get deleted, presumably because to
> > do so would leave dangling references, i.e. the two vars:
> >
> >                     var title = '' + this.args.title;
> >                     var mode = '' + this.args.mode;
> >
> >                     delete this.args['title'];
> >                     delete this.args['mode'];
>
> Oops, how I actually started was as follows (*without* making a copy
> of the string by prepending it with an empty string)
>
>                    var title = this.args.title;
>                    var mode = this.args.mode;
>
>                    delete this.args['title'];
>                    delete this.args['mode'];
>

Yes, that code will delete the title and mode properties from the this.args
object.

I'd go for consistent use of property names myself - you don't need to use
the quoted form:

                   var title = this.args.title;
                   var mode = this.args.mode;

                   delete this.args.title;
                   delete this.args.mode;

What didn't work? This code should do exactly what you expect. Your title
and mode variables now contain references to whatever was in this.args.title
and this.args.mode, but those two properties are now removed from this.args.
If console.log showed you something different, then there must be some other
code you didn't include in these snippets that is affecting it.

-Mike

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/jsmentors@jsmentors.com/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/jsmentors@googlegroups.com/

To unsubscribe from this group, send email to
jsmentors+unsubscr...@googlegroups.com

Reply via email to