Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Trying to make / use an array of objects

    This is what I got going on as far as declaring the class and the array:

    Code:
    function Toll(minX,minY,maxX,maxY) 
    {
    	this.minX=minX;
    	this.minY=minY;
    	this.maxX=maxX;
    	this.maxY=maxY;
    		
    	this.tollSlope = ((minY - maxY)/(maxX-minX));
        	
        	this.tollInter = minY - (tollSlope * maxX);
    }
    	
    Toll.method('getMinX', function () {
       			return this.minX;
    			});
    
    var myTolls = new Array()
    myTolls[0] = new Toll(-81.20961, 28.45135, -81.20945, 28.45173);
    and then later on in another function I try to call the getMinX function:

    Code:
    myTolls[0].getMinX
    but when I run this in IE I get an error that says myTolls is not an object...
    I am saying to myself of course myTolls is not an object. The value at element 0 in myTolls array is the object... what am i doing wrong?

    (first time poster so if I am doing this wrong give me a heads up)
    Last edited by iuse; 08-19-2007 at 11:32 PM.

  • #2
    New to the CF scene
    Join Date
    Aug 2007
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I am still having this problem. Does anyone know another way that I could create a class so that I can make multiple objects with the same kind of properties and methods?
    Does it seem what I am trying to do with the array and the class seem logical?
    any ideas or suggestions would be great.

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    From the code you've posted, I can see nothing that would go wrong in iew. One possible reason would be if the
    var myTolls = new Array()
    piece is in another script body which contains a syntax error, or in an external script file that gets loaded after the
    myTolls[0] = new Toll(-81.20961, 28.45135, -81.20945, 28.45173);
    piece.

    Could you show us the code in action?



    [aside]It's recommended that instead of using new Array() you should use []. It's smaller, stands out more, and is more consistent.[/aside]
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Of course, this was obvious after running it...
    Quote Originally Posted by iuse View Post
    Code:
    function Toll(minX,minY,maxX,maxY) 
    {
    	this.minX=minX;
    	this.minY=minY;
    	this.maxX=maxX;
    	this.maxY=maxY;
    		
    	this.tollSlope = ((minY - maxY)/(maxX-minX));
        	
    	this.tollInter = minY - (tollSlope* maxX);
    }
    tollSlope --> this.tollSlope
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • Users who have thanked liorean for this post:

    iuse (08-21-2007)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •