K
K
kylebRka2021-07-08 11:36:38
JavaScript
kylebRka, 2021-07-08 11:36:38

How to get a variable from an anonymous function? How do I get the X position of the mouse to be passed to the platform object?

let position = document.getElementById('position')
let mx
function callback(event){
    mx = event.pageX
}
window.onmousemove = callback
console.log(mx)

let platform = {
    x: mx - 100,
    y: 575,
    width: 200,
    height: 25,
    color: 'blue' 
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fedor Vlasenko, 2021-07-08
@kylebRka

x: _=>mx - 100,
//....
console.log(platform.x())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question