事件对象到底是什么?

发布于 2025-01-16 05:56:41 字数 790 浏览 2 评论 0原文

什么是事件对象?什么时候执行?为什么我们有它? 例如:

  1. 当我们像本例一样使用匿名函数时,事件对象将不是 renderPosts() 函数。

    window.addEventListener('DOMContentLoaded', () => renderPosts());
    
    const renderPosts = async () =>; {
      让 uri = 'http://localhost:3000/posts?_sort=likes&_order=desc';
      const res = 等待 fetch(uri);
      const container = document.querySelector(".blogs");```
    
    
  2. 当我们不使用匿名函数(如本例所示)时,事件对象将是 renderPosts() 函数。

    window.addEventListener('DOMContentLoaded',renderPosts());
    
    const renderPosts = async () =>; {
      让 uri = 'http://localhost:3000/posts?_sort=likes&_order=desc';
      const res = 等待 fetch(uri);
      const container = document.querySelector(".blogs");```
    
    
    

我没有看到其中的区别,也没有真正理解它。

What is an event object? When is it executed? Why do we have it?
For example:

  1. when we use an anonymous function as in this example, the event object will not be renderPosts() function.

    window.addEventListener('DOMContentLoaded', () => renderPosts());
    
    const renderPosts = async () => {
      let uri = 'http://localhost:3000/posts?_sort=likes&_order=desc';
      const res = await fetch(uri);
      const container = document.querySelector(".blogs");```
    
    
  2. when we do not use anonymous function as in this example, the event object will be renderPosts() function.

    window.addEventListener('DOMContentLoaded',renderPosts());
    
    const renderPosts = async () => {
      let uri = 'http://localhost:3000/posts?_sort=likes&_order=desc';
      const res = await fetch(uri);
      const container = document.querySelector(".blogs");```
    
    
    

I do not see the difference and not really understand it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文