0

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();                                                           
}
3

1 Answer 1

1

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();
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.