From b8c078527bf6f7dc61b68e61c13ec7c4d8c81364 Mon Sep 17 00:00:00 2001 From: Thujeevan Date: Sat, 7 Oct 2017 01:25:31 +0530 Subject: [PATCH] Replace arrow functions with standard functions fixes https://github.com/lap00zza/catch_me/issues/4 --- script.js | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/script.js b/script.js index e955fe3..b8c505f 100644 --- a/script.js +++ b/script.js @@ -7,10 +7,18 @@ const diff_enum = { }; // Utility Functions -const mv_x = (what, x) => what.style.left = x, - mv_y = (what, y) => what.style.top = y, - rand = (limit) => Math.random() * limit, - inRange = (lower, upper, what) => what >= lower && what <= upper; +const mv_x = function mv_x(what, x) { + return what.style.left = x; +}, + mv_y = function mv_y(what, y) { + return what.style.top = y; +}, + rand = function rand(limit) { + return Math.random() * limit; +}, + inRange = function inRange(lower, upper, what) { + return what >= lower && what <= upper; +}; // Selectors. Duh! const catch_me = document.getElementById("catch_me"), @@ -22,12 +30,22 @@ const catch_height = 50, catch_width = 100, difficulty = diff_enum.HARD; // CHANGE THIS FOR MORE FUN -const incr_counter = () => counter.innerText = +counter.innerText + 1; +const incr_counter = function incr_counter() { + return counter.innerText = +counter.innerText + 1; +}; // Next positions should be within the visible portion of the window. -const rand_x = () => rand(window.innerWidth - catch_width), - rand_y = () => rand(window.innerHeight - catch_height), - mv_catch_x = () => mv_x(catch_me, rand_x()), - mv_catch_y = () => mv_y(catch_me, rand_y()); +const rand_x = function rand_x() { + return rand(window.innerWidth - catch_width); +}, + rand_y = function rand_y() { + return rand(window.innerHeight - catch_height); +}, + mv_catch_x = function mv_catch_x() { + return mv_x(catch_me, rand_x()); +}, + mv_catch_y = function mv_catch_y() { + return mv_y(catch_me, rand_y()); +}; // Initial State catch_me.style.position = "absolute"; @@ -39,14 +57,14 @@ mv_catch_y(); // If you can get your mouse inside here you get a point. // But the question is, can you? ;) -catch_me.addEventListener("mouseenter", () => { +catch_me.addEventListener("mouseenter", function () { mv_catch_x(); mv_catch_y(); incr_counter(); }); // Track mouse movent inside body. -body.addEventListener("mousemove", e => { +body.addEventListener("mousemove", function (e) { const delta_x = e.offsetX - catch_me.offsetLeft, delta_y = e.offsetY - catch_me.offsetTop, xInRange = inRange(-difficulty, difficulty + catch_width, delta_x),