Reputation: 79
I am trying to call a function from within a class that is created outside of the class,but when I do JavaScript 'thinks' I am trying to write a new function. In the example below I make a class, I define a function(show), then I try to call a function not in the class(outsideFunction) but when I run my code I get an error
function outsideFunction(){
arc(100,75,50,0,2*Math.PI)
}
class example {
show(){
rect(20,20,150,100)
}
outsideFunction();
}
Upvotes: 0
Views: 116
Reputation: 1121
You are actually violating objected oriented concept. You can't call a function inside a class. You can call it in a member function like this:
function outsideFunction() {
arc(100, 75, 50, 0, 2 * Math.PI)
}
class example {
show() {
rect(20, 20, 150, 100)
}
outSideCaller() {
outsideFunction();
}
}
Upvotes: 1