Home arrow JavaScript arrow Page 2 - Properties and Methods of Custom 2D JavaScript Arrays
JAVASCRIPT

Properties and Methods of Custom 2D JavaScript Arrays


This is part two of a series that discusses custom 2D JavaScript arrays. In this part of the series, we see how to develop the properties and methods of our custom 2D array.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
October 14, 2009
TABLE OF CONTENTS:
  1. · Properties and Methods of Custom 2D JavaScript Arrays
  2. · The Constructor Function
  3. · The Array Object Type Methods
  4. · Adding Cells

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Properties and Methods of Custom 2D JavaScript Arrays - The Constructor Function
(Page 2 of 4 )

The constructor function is CustomArray(y,x). When it is called, y is the number of rows and x is the number of columns. At the end of this part, I will give you the complete code in a zip file.

The First Code Segment

As soon as the function is called, the following code is executed:

//Initial Processing

//form the row string

rowStr = "{"

for (j=0;j<y;j++)

{

if (j == 0)

rowStr += (j + ":" + "'" + undefined + "'");

else

rowStr += ("," + j + ":" + "'" + undefined + "'");

}

rowStr += "}";

 

This is the first code segment. It forms a string for the object initializer of the row. I explained this code in the previous part; I will not explain it again.

The next code segment is:

//form the rows

for (i=0;i<y;i++)

{

//form evaluation string

evalStr = "this[i] = " + rowStr + ";";

eval(evalStr);

}

This code segment forms the row properties of the object type (constructor function). Again, I explained this code in the previous part, and I will not explain it again.

The Height Property

The code segment that gives the height of the array is:

//The Array Object Type Properties

//the height property

this.height = y;

Giving the height of the array is simple. During construction of an array object, the y parameter is the number of rows, which we call the height. So we declare the word "height" here as a property of the object type with the expression, “this.height”; y is assigned to this property.


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 3 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials