简体   繁体   English

我如何理解这段 JavaScript 代码的含义?

[英]How can I understand what this JavaScript code means?

What does this JavaScript code mean?这段 JavaScript 代码是什么意思?

img.file = file;

const reader = new FileReader();
reader.onload = (function(aImg) { 
    return function(e) { 
        aImg.src = e.target.result; 
    }; 
})(img);

Specifically this具体来说这个

reader.onload = (function(){...})()

This is an Immediately Invoked Function Expression (IIFE)这是一个立即调用函数表达式 (IIFE)

https://developer.mozilla.org/en-US/docs/Glossary/IIFE would be helpful in your case. https://developer.mozilla.org/en-US/docs/Glossary/IIFE会对您的情况有所帮助。

It creates a function and immediately calls it.它创建一个函数并立即调用它。 You can find some use cases in the link above您可以在上面的链接中找到一些用例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何才能详细了解这个 javascript 计时器的含义? - How can I understand what this javascript timer means in detail? 我在理解此javascript代码段的含义时遇到了麻烦。 有人可以逐行发表评论吗? - I'm having trouble understand what this javascript code snippet means. Can someone give comments line by line? 我不明白这个小代码块是什么意思 - I do not understand what this small block of code means 这段代码在javascript中是什么意思 - what is means of this code in javascript 我如何理解edittext中的javascript或jquery代码? - How can I understand javascript or jquery code inside in edittext? 我不明白这段代码有什么错误 - I can't understand what is the error in this code 我需要帮助阅读此代码以了解它在做什么,以便我可以将其转换为 javascript - I need help reading this code to understand what it is doing so I can convert it to javascript $在JavaScript中是什么意思,如何在Win8应用程序中替换它? - What does $ means in JavaScript and how can I replace it in a Win8 application? 有人可以帮助我理解为什么此JavaScript代码不起作用以及如何解决该问题吗? - Can somebody help me understand why this JavaScript code won't work, and how I can fix it? 我无法理解这段代码是如何工作的 - I can't understand how this code works
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM