课程: JavaScript: The Tricky Bits

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Pain point: Send extra parameters to an event handler

Pain point: Send extra parameters to an event handler - JavaScript教程

课程: JavaScript: The Tricky Bits

Pain point: Send extra parameters to an event handler

- [Joe] This section is roughly grouped under the heading of functions, starting with this video where we're looking at event handlers and other functions where there's an expected parameter or set of parameters. Is it possible to add to those parameters, and if so, how? If you've written anything JavaScript for the web, you've surely written an event handler like this countless times. You pass the event object if needed inside the function. And if you need other contexts, it comes from variables to find outside the function. The same logic generally applies to other uses of callback functions like timers, promises, and AJAX requests. There's usually some known parameters passed in and that's it, or at least that's how it appears. This can start to feel limiting when your callback function could use a little more context that isn't immediately available. It can be especially tricky when you're depending on external…

内容