On Feb 2, 11:46 am, Andrew Poulos <ap_p...@hotmail.comwrote:
Why is it that if I do this:
Foo = function() {
this.prop = true;};
Foo.prototype.hi = function() {
alert("hi");};
bar = new Foo();
delete bar;
bar.hi();
nothing gets alerted.
But you do get an error report (you should look at/for error reports).
But if I change the call to the constructor to
var bar = new Foo();
then the alert gets fired. And if I do this:
Variables declared in function or global execution contexts are marked
with the - DontDelete - attribute and so cannot be deleted (the delete
operation evaluates as false instead of true to indicate its falure
(sort of)).
Foo = function() {
this.prop = true;};
Foo.prototype.hi = function() {
delete this;};
bar = new Foo();
bar.hi();
Why would it? You have attempted to delete - this -, which is not
possible as - this - does not evaluate as a Reference type (it is a
value that is a reference to an object), and so the delete operator
does not act at all (but the delete expression still evaluates as true
in this case).
In any event, the - delete - operator works only by removing
properties from objects (where they are not marked as - DontDelete -)
and whatever object is referred to by - this - does not know which
properties of other objects (including Variable objects) may refer to
it, if any).
Richard.