如果读过MDN
的话,应该会注意到MDN
上对JavaScript
的定义部分是这样写的:
JavaScript (JS) is a lightweight interpreted or JIT-compiled programming language with first-class functions. While it is most well-known as the scripting language for Web pages, many non-browser environments also use it, such as node.js and Apache CouchDB. JavaScript is a prototype-based, multi-paradigm, dynamic language, supporting object-oriented, imperative, and declarative (e.g. functional programming) styles. Read more about JavaScript.
开篇定义中便提到了函数优先(First-class Function),也即通常所说的JavaScript
中的一等公民Funciton
。
那问题来了:这个一等公民为什么会被称作一等公民呢?哪些特征让函数在JavaScript
中成为了一等公民?