New to JavaScript. I'm trying to call a method of an object passed as an argument to another method. I keep getting the error that the argument is null or the argument doesn't have a method named x.
In a strongly typed language like c# you can do this
public class Context
{
public void moveTo(int x, int y) {...}
public void lineTo(int x, int y) {...}
}
public class Square
{
public void draw(Context c, int x, int y) {
c.moveTo(x,y);
c.lineTo(x+10,y+5); //etc
}
}
public class Design
{
ctx = new Context();
s = new Square();
s.draw(ctx,5,10);
}
Instead of a Square, I'm drawing something more complex. But in my attempt at Javascript, when it compiles it gets an error in draw that c is null, has no method lineTo.
What is the Javascript way of doing this?