From: abozhilov on
E262-3 edition
11.4.1 The delete Operator
The production UnaryExpression : delete UnaryExpression is evaluated
as follows:
1. Evaluate UnaryExpression.
2. If Type(Result(1)) is not Reference, return true.
3. Call GetBase(Result(1)).
4. Call GetPropertyName(Result(1)).
5. Call the [[Delete]] method on Result(3), providing Result(4) as the
property name to delete.
6. Return Result(5).

I don't understand something about the delete operator.
If i have code like this.

window.foo = {};
var bar = foo;
delete window.foo;
alert(window.foo);
alert(bar);

1. Attach `foo` property to Global Object. assigned to `foo` reference
to `object`.
2. Copy reference from `foo` and assigned to bar.
3. delete window.foo, will be delete `foo` property. Just delete
reference to `object`.
4. Results will be `undefined`. Logical.
5. Results will be `[object Object]`


What do `delete` operator when i delete reference? Just marked
`object` to garbage collection, if doesn't have any other reference to
that `object` in any scope? In my case created object from that line:

window.foo = {};

That object will be deleting after reload my page. Not reference, i
talk about `object`. Because i have reference to that object in global
scope:

var bar = foo;

If i have code like this:

window.foo = {};
(function()
{
var bar = foo;
delete window.foo;
alert(window.foo);
alert(bar);
})();

When `object` will be deleting? The last reference to that object is
in the anonymous function scope. I thing after executing anonymous
function that object will be delete. Because `bar` variable have local
scope.

Thanks.


From: John G Harris on
On Sun, 6 Sep 2009 at 07:12:35, in comp.lang.javascript, abozhilov
wrote:

<snip>
>What do `delete` operator when i delete reference?
<snip>

The 'delete' operator deletes an object property. If the property's
value happens to be a reference to an object then that object is not
changed.

There is no way in javascript to delete an object. All you can do is
remove all references to it. The garbage collector will destroy the
object when it needs the storage space for something else. Possibly the
garbage collector will destroy the object sooner than that, but it isn't
guaranteed. You've no way of finding out which happened.

John
--
John Harris
From: Thomas 'PointedEars' Lahn on
abozhilov wrote:
> E262-3 edition
> 11.4.1 The delete Operator
> The production UnaryExpression : delete UnaryExpression is evaluated
> as follows:
> 1. Evaluate UnaryExpression.
> 2. If Type(Result(1)) is not Reference, return true.
> 3. Call GetBase(Result(1)).
> 4. Call GetPropertyName(Result(1)).
> 5. Call the [[Delete]] method on Result(3), providing Result(4) as the
> property name to delete.
> 6. Return Result(5).
>
> I don't understand something about the delete operator.
> If i have code like this.
>
> window.foo = {};
> var bar = foo;
> delete window.foo;
> alert(window.foo);
> alert(bar);
>
> 1. Attach `foo` property to Global Object. assigned to `foo` reference
> to `object`.

No. How and where did you get the idea that the host object referred to by
`window' would be generally identical with the native ECMAScript Global
Object? Evidently it isn't, and because it is a host object you should not
attempt to augment it with user-defined properties.

Use `this' in the global execution context to refer to the ECMAScript Global
Object.

See also: <https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference>

> 2. Copy reference from `foo` and assigned to bar.

I would not use the word "copy" here. The reference is a *value* and so
simply assigned (read from A, written to B). Think of it as a number, say
42; that will make things easier to understand.

> 3. delete window.foo, will be delete `foo` property.

Which *might* delete the `foo' property. You are dealing with a host object
here. See below.

> Just delete reference to `object`.

No.

> 4. Results will be `undefined`. Logical.

The result is `undefined' because there is not a property with such a name
anymore; _not_ because the reference was deleted. The reference is a value
and may well continue to exist in memory without being accessible by code.

> 5. Results will be `[object Object]`

As the string representation of (Object) objects is not specified or fixed,
the result may be anything here. In particular, the string representation
of an object is known to be implementation-dependent.

`alert()', or better `window.alert()', is not a suitable means to detect
anything if you don't know what you (and it) are doing.

> What do `delete` operator when i delete reference?

The `delete' operator deletes properties from objects, not references.

> Just marked `object` to garbage collection, if doesn't have any other reference to
> that `object` in any scope?

If, before the deletion attempt, the property stored an object reference,
the object being referred to is going to be marked for garbage collection
iff that was the last reference to that object (much like a hardlink in the
filesystem).

> In my case created object from that line:
>
> window.foo = {};
>
> That object will be deleting after reload my page.

*Maybe*. First of all, `window' refers to a host object; second, garbage
collection is entirely at the disposal of the implementation.

> Not reference, i talk about `object`. Because i have reference to that
> object in global scope:
>
> var bar = foo;

The global `bar' variable is a property of the global Variable Object, which
is the ECMAScript Global Object. Whether that object is destroyed *before*
reload, and the memory allocated for storing its properties is freed,
depends on the implementation and on the runtime environment it is used by.
Logic and experience suggests that at least all its properties are deleted
before reload.

> If i have code like this:
>
> window.foo = {};
> (function()
> {
> var bar = foo;
> delete window.foo;
> alert(window.foo);
> alert(bar);
> })();
>
> When `object` will be deleting?

At some unspecified point in time after the `delete' operation, hopefully.
However, the property will be deleted immediately, unless the host object
referred to by `window' does not allow it, or the property may have, despite
its being user-defined, the `DontDelete' attribute (as a host object, the
object referred to by `window' may implement a [[Put]] or [[Delete]] method
that does not follow the specified ECMAScript algorithms).

> The last reference to that object is in the anonymous function scope.
> I thing after executing anonymous function that object will be delete.
> Because `bar` variable have local scope.

The object might be marked for garbage collection then. That is quite
different from deletion in the sense of deallocation, which happens at some
point in time later, hopefully.


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
From: abozhilov on
On Sep 6, 10:30 pm, Thomas 'PointedEars' Lahn <PointedE...(a)web.de>
wrote:
> abozhilov wrote:
> > 1. Attach `foo` property to Global Object. assigned to `foo` reference
> > to `object`.
>
> No.  How and where did you get the idea that the host object referred to by
> `window' would be generally identical with the native ECMAScript Global
> Object?  Evidently it isn't, and because it is a host object you should not
> attempt to augment it with user-defined properties.
>
> Use `this' in the global execution context to refer to the ECMAScript Global
> Object.
>
> See also: <https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference>

In this case, you are absolutely right. That is my error. My web
development bending. Thanks. This is good point. "this" keyword is
best in this case to referred Global Object.

>
> > 2. Copy reference from `foo` and assigned to bar.
>
> I would not use the word "copy" here.  The reference is a *value* and so
> simply assigned (read from A, written to B).  Think of it as a number, say
> 42; that will make things easier to understand.
>
> > 3. delete window.foo, will be delete `foo` property.
>
> Which *might* delete the `foo' property.  You are dealing with a host object
> here.  See below.
>
> > Just delete reference to `object`.
>
> No.
>
> > 4. Results will be `undefined`. Logical.
>
> The result is `undefined' because there is not a property with such a name
> anymore; _not_ because the reference was deleted.  The reference is a value
> and may well continue to exist in memory without being accessible by code..

Exactly. That i want to say. Just illustrate what been deleted from
`foo` property. The delete operator simply delete property from
`object`.

>
> > 5. Results will be `[object Object]`
>
> As the string representation of (Object) objects is not specified or fixed,
> the result may be anything here.  In particular, the string representation
> of an object is known to be implementation-dependent.
>
> `alert()', or better `window.alert()', is not a suitable means to detect
> anything if you don't know what you (and it) are doing.
>

In this case you are right. But if i use.
Object.prototype.toString. We get internal [[Class]] property.
In my case:
alert(window.foo);
equivalent to:
alert(window.foo.toString());
If someone predefined toString method of that object, we have another
results. In this case you are absolutely right.
Again good point.

> > What do `delete` operator when i delete reference?
>
> The `delete' operator deletes properties from objects, not references.
>
> > Just marked `object` to garbage collection, if doesn't have any other reference to
> > that `object` in any scope?
>
> If, before the deletion attempt, the property stored an object reference,
> the object being referred to is going to be marked for garbage collection
> iff that was the last reference to that object (much like a hardlink in the
> filesystem).
>
> > In my case created object from that line:
>
> > window.foo = {};
>
> > That object will be deleting after reload my page.
>
> *Maybe*.  First of all, `window' refers to a host object; second, garbage
> collection is entirely at the disposal of the implementation.
>
> > Not reference, i talk about `object`. Because i have reference to that
> > object in global scope:
>
> > var bar = foo;
>
> The global `bar' variable is a property of the global Variable Object, which
> is the ECMAScript Global Object.  Whether that object is destroyed *before*
> reload, and the memory allocated for storing its properties is freed,
> depends on the implementation and on the runtime environment it is used by.
>  Logic and experience suggests that at least all its properties are deleted
> before reload.
>
> > If i have code like this:
>
> > window.foo = {};
> > (function()
> > {
> >    var bar = foo;
> >    delete window.foo;
> >    alert(window.foo);
> >    alert(bar);
> > })();
>
> > When `object` will be deleting?
>
> At some unspecified point in time after the `delete' operation, hopefully..
> However, the property will be deleted immediately, unless the host object
> referred to by `window' does not allow it, or the property may have, despite
> its being user-defined, the `DontDelete' attribute (as a host object, the
> object referred to by `window' may implement a [[Put]] or [[Delete]] method
> that does not follow the specified ECMAScript algorithms).
>
> > The last reference to that object is in the anonymous function scope.
> > I thing after executing anonymous function that object will be delete.
> > Because `bar` variable have local scope.
>
> The object might be marked for garbage collection then.  That is quite
> different from deletion in the sense of deallocation, which happens at some
> point in time later, hopefully.
>
> PointedEars
> --
> var bugRiddenCrashPronePieceOfJunk = (
>     navigator.userAgent.indexOf('MSIE 5') != -1
>     && navigator.userAgent.indexOf('Mac') != -1
> )  // Plone, register_function.js:16

After your post my example look like this:

this.foo = {};
var bar = this.foo;
delete this.foo;
alert(this.foo);
alert(Object.prototype.toString.call(bar));

Thanks Thomas for your usefully posts.
From: Thomas 'PointedEars' Lahn on
abozhilov wrote:
> Thomas 'PointedEars' Lahn wrote:
>> abozhilov wrote:
>>> 5. Results will be `[object Object]`
>> As the string representation of (Object) objects is not specified or fixed,
>> the result may be anything here. In particular, the string representation
>> of an object is known to be implementation-dependent.
>>
>> `alert()', or better `window.alert()', is not a suitable means to detect
>> anything if you don't know what you (and it) are doing.
>
> In this case you are right. But if i use.
> Object.prototype.toString. We get internal [[Class]] property.

Iff the specified algorithm is used; you cannot know that, not even if you
explicitly call Object.prototype.toString(). That is, if the object
implements its own toString() method or is a host object, the string
representation would not be known. And however unfortunate and apparently
not standards-compliant, an implementation may even defined its own
Object.prototype.toString() algorithm that contradicts what is specified.
Only time will tell if there is such an implementation that needs to be
taken seriously.

> Thanks Thomas for your usefully posts.

You are welcome. But *please* trim your quotes to the necessary *minimum*
to retain context; do _not_ quote signatures (unless you are referring to them).

See also: <http://jibbering.com/faq/#posting>


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm> (404-comp.)