camwiegert/in-view

Uncaught ReferenceError

dkdl opened this issue · 2 comments

dkdl commented

I get a Uncaught ReferenceError: el is not defined when I call it like this:

inView('.about video')
  .on('enter', console.log(el) );

Due to restrictions I cannot use the ES6 arrow function. How can I fix this?

@dkdl You're getting that because you're passing the result of invoking console.log(el) (el doesn't exist at that point) instead of a function. What you'll want to do is this:

inView('.about video')
    .on('enter', function(el) {
        console.log(el);
        // ...
    });

If you just want to log the element, you could do this:

inView('.about video')
    .on('enter',  console.log.bind(console));

Hope that helps!

dkdl commented

@camwiegert thank you for explaining the problem. I understand now what I did wrong 👍