473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

using delete

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 if I change the call to the constructor to

var bar = new Foo();

then the alert gets fired. And if I do this:

Foo = function() {
this.prop = true;
};
Foo.prototype.hi = function() {
delete this;
};
bar = new Foo();
bar.hi();

the object 'bar' does not seem to have been deleted? I'm testing with FF 2.

Andrew Poulos
Feb 2 '07 #1
3 1179
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.

Feb 2 '07 #2
Richard Cornford wrote:
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)).
Interesting gotcha.
Feb 4 '07 #3
pcx99 wrote:
Richard Cornford wrote:
>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)).

Interesting gotcha.
Why is that a "gotcha"? There is no particularly good reason for wanting
to delete declared variables so not being able to is is hardly an
inconvenience.

Richard.

Feb 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: doomx | last post by:
I'm using SQL scripts to create and alter tables in my DB I want to know if it's possible to fill the description(like in the Create table UI) using these scripts. EX: CREATE TABLE(...
9
by: Ben Dewey | last post by:
Project: ---------------------------- I am creating a HTTPS File Transfer App using ASP.NET and C#. I am utilizing ActiveDirectory and windows security to manage the permissions. Why reinvent...
2
by: createdbyx | last post by:
I am trying to make a file sync utillity to sync files between my laptop and my desktop pc. On my desktop machine (xp pro sp2) I have shared my "Visual Studio Projects" folder using windows simple...
1
by: Robert Fitzpatrick | last post by:
I am running PostgreSQL 7.4.5 and have a trigger on a table called tblriskassessors which inserts, updates or delete a corresponding record in tblinspectors by lookup of a contact id and license...
2
by: Brad | last post by:
I have a web .Net app which sends emails with attachments. After the email is sent I clean up aftermyself and delete the attachments from disk. In upgrading to .Net 2 I changed the email logic...
4
by: Wannabe | last post by:
I am using ASP.Net 2.0 and have a gridview on my page. I have everything working except the delete command. The page reloads except the row I am trying to delete is still there. I believe it is...
9
by: Money | last post by:
If I allocate memory like this int *ptr = new int; Can I apply delete ptr; instead of delete ptr; since I am only allocating memory for 1 integer.
1
by: tezza98 | last post by:
I need some help. Im using a dtsrun command to import 9 tables into an Access database, most of the tables have about 1000 rows, but one has 20000+ rows and grows everyday. Im Using Access 2003...
8
by: Chris Portka | last post by:
I need to be able to allocate large numbers of elements at a time but then delete them one at a time. I have settled on the design of using new to allocate many items at once, but am unsure what...
9
by: itdevries | last post by:
Hi, I've ran into some trouble with an overloaded + operator, maybe someone can give me some hints what to look out for. I've got my own custom vector class, as a part of that I've overloaded...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.