JavaScript
  Home arrow JavaScript arrow Deleting JavaScript Properties and Methods
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Deleting JavaScript Properties and Methods
By: Chrysanthus Forcha
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2009-10-02

    Table of Contents:
  • Deleting JavaScript Properties and Methods
  • Deleting Properties and Methods
  • Properties and Methods Belonging Only to a Particular Object
  • Object Type Properties and Methods with Particular Object Assignment
  • Object Type Properties and Methods in a Constructor Function

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Deleting JavaScript Properties and Methods


    (Page 1 of 5 )

    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).

    Adding Properties and Methods to Objects

    In this section I explain how you can add properties and methods to objects; that is, to instances of object types.

    This is a code segment showing what we had in the example at the end of the previous part.

    function ObjectType()

    {

    this.propertyType1 = "Yes type one";

    this.methodType1 = functionType1;

    }


    ObjectType.prototype.propertyType2 = null;

    ObjectType.prototype.methodType2 = null;


    var theObject = new ObjectType();

    We have the ObjectType object type, and we have the object derived from it, theObject. You can add properties and methods to the theObject instance. When you do this, the property name, the method name, the property assigned value and the method assigned function will not occur in the object type; they will not occur in other objects (instances) of the object type (class).

    After the object has been created with the new operator, to add a property whose value is “Yes one,” you would type,

    theObject.property1 = "Yes one";

    After the object has been created with the new operator, to add a method to which the function1() function is assigned, you type,

    theObject.method1 = function1;

    The function1() function should exist in the code.

    This is how you add a property or a method that will belong only to the object (instance) concerned. The approach is the same as is would be if you were simply assigning a value or function to a property or method of an object whose property or method had been declared for the object type (as in the last part).

    The following code illustrates what we have just learned:

    <html>

    <head>

    <script type="text/JavaScript">

    function functionType1()

    {

    alert('This is function type one');

    }


    function functionType2()

    {

    alert('This is function type two');

    }


    function function1()

    {

    alert('This is function one');

    }


    function ObjectType()

    {

    this.propertyType1 = "Yes type one";

    this.methodType1 = functionType1;

    }


    ObjectType.prototype.propertyType2 = null;

    ObjectType.prototype.methodType2 = null;


    var theObject = new ObjectType();


    theObject.propertyType2 = "Yes type two";

    theObject.methodType2 = functionType2;


    theObject.property1 = "Yes one";

    theObject.method1 = function1;

    </script>

    </head>

    <body>

    <button type="button" onclick="alert(theObject.property1)">Display property 1</button>

    <button type="button" onclick="theObject.method1()">Call Method 1</button>

    </body>

    </html>

    When you click the first button, the value of the theObject’s only property we have just added is displayed. When you click the second button, the theObject’s only method we have just added is executed.

    More JavaScript Articles
    More By Chrysanthus Forcha


     

    JAVASCRIPT ARTICLES

    - Toggling CSS Properties with the GX JavaScri...
    - Cancel, Queue and Pause Animations with the ...
    - Producing Elastic Effects with the GX JavaSc...
    - Moving Divs Diagonally with the GX JavaScrip...
    - Moving Elements Vertically and Horizontally ...
    - Making Bouncing Effects in Parallel with the...
    - Creating Bouncing Effects with the GX JavaSc...
    - Manipulating Background Colors with the GX J...
    - The GX JS Animation Framework
    - Debug Ajax-Generated Tags in Firefox
    - Building a Page Controller with the jQuery Q...
    - Paginating Database Records with the jQuery ...
    - Paginating Images with the jQuery Quick Pagi...
    - Hiding the Page Counter with the jQuery Quic...
    - Introducing the Quick Pagination jQuery Plug...







    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 12 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek