Home arrow JavaScript arrow Page 4 - Nested JavaScript Functions as Objects
JAVASCRIPT

Nested JavaScript Functions as Objects


In this conclusion to a three-part series on nesting JavaScript functions, we see how nested functions can be used as object types. We shall make it simple. We shall consider only the case where there is only one level of nested functions.

Author Info:
By: Chrysanthus Forcha
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
October 22, 2009
TABLE OF CONTENTS:
  1. · Nested JavaScript Functions as Objects
  2. · Constructor Function
  3. · Nested Function as Method
  4. · Position of Nested Function in the Constructor
  5. · My method of coding JavaScript Constructor Function

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Nested JavaScript Functions as Objects - Position of Nested Function in the Constructor
(Page 4 of 5 )

The question here is, “should you define a function in the constructor before you assign it as a method, or should you assign it as a method before you define it in the constructor?”

The following two constructor functions are the same.

This one:

function ObjectType()

{

this.propertyType1 = "Yes type one";


function functionType2()

{

alert('This is function type two');

}

this.methodType2 = functionType2;

}


and this one:


function ObjectType()

{

this.propertyType1 = "Yes type one";


this.methodType2 = functionType2;


function functionType2()

{

alert('This is function type two');

}

}

In the first case the function is defined before it is assigned as a method. In the second case it is assigned before it is defined as a method. Both constructor functions work in JavaScript. It does not matter whether you assign the method before you define it, or define it before you assign it.


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