JavaScript help required

Log in to stop seeing adverts
This page may contain links to companies such as eBay and Amazon. As an affiliate of these sites I may earn commission if you click the link and make a purchase

Status
Not open for further replies.

Matt_B

Well-Known Member
Right, this is driving me round the fecking bend. I have a JavaScript object and am trying to do the following concept:

Code:
function SomeObject(parameter1, parameter2){

this.par1 = parameter1;
this.par2 = parameter2;

this.AnInternalFunctionToCall(){
//do something
}

this.AnotherFunction(){
//do some stuff then try to call the other function declared
this.AnInternalFunctionToCall();
}

}

I can do the following no problem:

var obj = new SomeObject(a,b);
obj.AnInternalFunctionToCall();

but when I try to call obj.AnotherFunction() it throws the error "this.AnInternalFunctionToCall is not a function"

Surely an internal method can call a method on itself? Any constructive help is appreciated!
 
Don't worry about it, I just figured out that in a JS object methods can't access other public methods, to solve the following I would need to do:

Code:
function SomeObject(parameter1, parameter2){

this.par1 = parameter1;
this.par2 = parameter2;

[COLOR="Red"]function AnInternalFunctionToCall(){
AnInternalFunctionToCall();
}[/COLOR]

this.AnInternalFunctionToCall(){
//do something
}

this.AnotherFunction(){
//do some stuff then try to call the other function declared
this.AnInternalFunctionToCall();
}

}

Note the new bit in red. How very stupid.
 
Status
Not open for further replies.
Log in to stop seeing adverts

P Pld Pts
1Liverpool1639
2Chelsea1735
3Arsenal1733
4Nottm F1731
5Bournemouth1728
6Aston Villa1728
7Manchester C  1727
8Newcastle1726
9Fulham1725
10Brighton1725
11Tottenham 1723
12Brentford1723
13Manchester U1722
14West Ham1720
15Everton1616
16Palace1716
17Leicester1714
18Wolves1712
19Ipswich1712
20Southampton176

Latest posts

Back
Top