The delete operator removes the property with a given name from an
object unless the property has the DontDelete attribute. This is
specified in the ECMA-262 standard in section 8.6.2.5. Variables
introduced in global code or function code using "var x = value" will
have the DontDelete attribute and the delete operator will return
false for such variables and it will not remove them. Variables
introduced using eval or by assigning to a property that does not yet
exist will not have the DontDelete attribute and the delete operator
will remove such variables.
Here are a couple of examples:
> var x = 42;
> delete x;
false;
> x
42
> function f() { var x = 42; delete x; return x; }
> f()
42
> eval("var y = 1")
> delete y
true
> y
(shell):1: ReferenceError: y is not defined
> z = 42
42
> delete z
true
> z
(shell):1: ReferenceError: z is not defined
> var o = {}
> o.x = 42
42
> delete o.x
true
> o.x == undefined
true
Cheers, -- Mads
On Wed, Oct 22, 2008 at 8:16 PM, <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> i've a question about the delete operator.
>
> Seeing the Point test/example from Jacob Burbach, I encountered some
> questions like this one...
>
> the meaning of the delete operator... Does this operator should not
> remove the object, and make the var reference invalid?
> For example if in the Shell example i put "var prueba=new String("Hola
> Mundo"); delete x;" i see in the console a "false" result, and the
> object is still alive.
>
> Why this hapens? what is the behavior of this operator?
>
> Thanks in advance
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---