Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-18-2007, 11:37 PM   PM User | #1
iuse
New to the CF scene

 
Join Date: Aug 2007
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
iuse is an unknown quantity at this point
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 10:32 PM..
iuse is offline   Reply With Quote
Old 08-20-2007, 12:10 PM   PM User | #2
iuse
New to the CF scene

 
Join Date: Aug 2007
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
iuse is an unknown quantity at this point
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.
iuse is offline   Reply With Quote
Old 08-20-2007, 12:53 PM   PM User | #3
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
From the code you've posted, I can see nothing that would go wrong in iew. One possible reason would be if the
Quote:
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
Quote:
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
liorean is offline   Reply With Quote
Old 08-20-2007, 01:00 PM   PM User | #4
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
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
liorean is offline   Reply With Quote
Users who have thanked liorean for this post:
iuse (08-21-2007)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:28 PM.


Advertisement
Log in to turn off these ads.