Y
Y
yankoyski2018-03-18 08:11:07
JavaScript
yankoyski, 2018-03-18 08:11:07

How can I optimize/reduce the code?

The code returns the actual value of the "y" variable, which is updated on scroll and writes the value to "f".

let f = (function () {

    let y = (function () {

        let result = 1;

        return function () {

            return result ++;
        };
    })();

    $(window).on("scroll", function() {

        return f = y();
    });
})();

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem Spiridonov, 2018-03-18
@customtema

Thank you, I remembered the useless let.
And why all this?

T
twobomb, 2018-03-18
@twobomb

I do not understand why you need this value, but I can tell you with certainty that this is not a scroll value relative to the page. The code can be done like this

(function(){
  var result = 1;
    $(window).on("scroll", function() {
        result++;
    });

})();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question