Home arrow JavaScript arrow Page 2 - Deleting JavaScript Properties and Methods
JAVASCRIPT

Deleting JavaScript Properties and Methods


Welcome to the second part of a three-part series on adding and deleting JavaScript properties and methods. In this part of the series, we learn how to delete properties and methods. Before we get into that, let us see how to add properties and methods to objects (instances).

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
October 02, 2009
TABLE OF CONTENTS:
  1. · Deleting JavaScript Properties and Methods
  2. · Deleting Properties and Methods
  3. · Properties and Methods Belonging Only to a Particular Object
  4. · Object Type Properties and Methods with Particular Object Assignment
  5. · Object Type Properties and Methods in a Constructor Function

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Deleting JavaScript Properties and Methods - Deleting Properties and Methods
(Page 2 of 5 )

There is an operator called the delete operator. The specification says this operator can delete an object’s property. It does not say whether or not it can delete a method. The specification also says that it can delete user-defined property.

We have to carry out our own investigations to learn whether it can delete a method that belongs only to one object; whether it can delete a property or a method that belongs to all objects (object type); and whether it can delete a property or method in the object type constructor function. It is not clear from the specification if we can achieve this. 

I used Internet Explorer, Mozilla Firefox, Netscape, Opera and Safari to carry out these investigations. I give you the results in this section. The syntax to delete a property is:

delete objectName.property

This operation returns true if it succeeds in deleting the property. It returns false if it does not succeed in deleting the property. If the delete operator succeeds, it sets the property or element to undefined (that is what is in the specification).

We shall use the above code for our investigations. Our test for the three cases is simple: we shall attempt to delete a property or method, and then display the returned Boolean value. If the Boolean value returned from the operation is true for all the browsers, then it means the property or method was deleted. To really be sure, we shall try to display the value of the deleted property or execute the method.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials