function到底啥意思?

function中文解释 - 通俗易懂版
字数: 1,800字 领域: 编程/数学 完成时间: 2023-12-15
原文 (English)

Function is a fundamental concept in programming and mathematics that refers to a block of organized, reusable code or a relation between inputs and outputs.

In programming, a function is a self-contained module of code that accomplishes a specific task.

The term "function" also has other meanings:

1. In mathematics, a relation that associates each element of a set with exactly one element of another set

2. The purpose or role that something is designed to perform

3. A formal ceremony or social gathering

译文 (中文)

function这词儿啊,在编程和数学里头可太重要了,说白了就是一段能重复使用的代码块儿,或者是输入和输出之间的关系。

在编程这块儿,function就是个独立的小模块,专门干一件特定的事儿,跟咱们平时说的"功能"差不多意思。

"function"这词儿还有其他几个意思呢:

1. 数学里头说的函数,就是一个集合里的每个元素都对应着另一个集合里的唯一元素

2. 指某个东西设计出来要干的事儿,比如"手机的功能"

3. 正式场合的聚会或者仪式,比如"公司年会"

补充说明:在JavaScript里头写function的时候,老手们都爱用箭头函数(=>),这玩意儿写起来倍儿方便!不过初学者还是先把普通函数整明白再说。