Quick Javascript question regarding Vue custom 'scroll' directive from the VueJS cookbook

I am learning VueJS from the VueJS documentation. In particular, I am in the topic on custom directives at the moment. I reference the docs if anyone needs more information..

VueJS Creating Custom Scroll Directives – #base example

With the custom-directive code block below:

 Vue.directive('scroll', {
  inserted: function (el, binding) {
    let f = function (evt) {
      if (binding.value(evt, el)) {
        window.removeEventListener('scroll', f)
      }
    }
    window.addEventListener('scroll', f)
  }
})

…I am having trouble wrapping my head with respect to the (binding.value(evt, el)) expression for the IF statement within the f function. Could someone please explain to me what the expression means? I’m thinking that the IF block is there to improve performance by removing the event listener between each ‘scroll’ event? I however never heard that it was required to remove the event listener. I would appreciate if someone could provide a more concise explanation on what it does and why its done that way.

Thank you very much for your time!

73 thoughts on “Quick Javascript question regarding Vue custom 'scroll' directive from the VueJS cookbook”

  1. Pingback: viagra connect
  2. Pingback: viagra sample
  3. Pingback: get cialis
  4. Pingback: viagra canada
  5. Pingback: generic viagra

Leave a Comment