Objects created from class says not defined

I was trying to make a simple game , and learn the Es6 modules on the way but i am now stuck in this unusall problem , i made a classs in module file called Ball() and it has increaseY() method … But when i instansiate the object of Ball and try to use the increaseY() method ,it says ball1 is undefined but why?
my main script file

import {Ball} from './objects.js';
function fallingBalls(){
const ball1=new Ball(250,screen).draw();
ball1.increaseY();
}

and my module file i.e objects.js is

export class Ball{
    constructor(xPos,screen,beginPos){
        this.xPos=xPos;
        this.screen=screen;
        this.beginPos=beginPos
    }
    draw(){
    this.screen.beginPath();
    this.screen.arc(this.xPos, 75, 50, 0, 2 * Math.PI);
    this.screen.stroke();
    }
    increaseY(){
    	xPos+=5;`

the console error log is

TypeError: ball1 is undefined

sorry my bad ,
i should have done

var ball1= new Ball(...args);

not

var ball1= new Ball(...args).draw();

since draw method didn’t return anything. :slight_smile:

You assigned the result of calling the draw method to ball1. You did not post the full Ball class definition. What does the draw method return?

1 Like

thanks but i figured it out just few seconds before your solution.