JavaScript function lacks return value
P粉310931198
P粉310931198 2023-09-06 21:39:23
0
1
281

This is probably something very simple and stupid, but why doesn't it return anything? I have this simple class method:

checkCollision(event) {
        let eventX = event.clientX - canvasRect.left;
        let eventY = event.clientY - canvasRect.top;
        if (this.centerX - eventX <= this.radiusX && this.centerX - eventX >= (this.radiusX/-1) && this.centerY - eventY <= this.radiusY && this.centerY - eventY >= (this.radiusY/-1)) {
            console.log(true);
            return true;
        } else {
            console.log(false);
            return false;
        }
    }

But when running in the browser, its output is

> obj.checkCollision({clientX: 200, clientY: 200})
false
<- undefined

Why doesn't it return anything? console.log is running but no return value

P粉310931198
P粉310931198

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!