“头等对象”是什么意思? [英] What is meant by 'first class object'?

查看:128
本文介绍了“头等对象”是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近的问题中,我收到了建议其中包括JavaScript的方面,其中函数是第一类对象。与其他对象相比,第一类在这种情况下意味着什么?

In a recent question, I received suggestions to talk on, amongst other things, the aspect of JavaScript where functions are 'first class' objects. What does the 'first class' mean in this context, as opposed to other objects?

EDIT(JörgWMittag):完全重复:什么是一流的编程结构?

EDIT (Jörg W Mittag): Exact Duplicate: "What is a first class programming construct?"

推荐答案

引用维基百科


在计算机科学中,编程
语言据说支持
一等函数(或函数
literal)如果它首先将函数视为
- 类对象。具体来说,
这意味着该语言支持

执行程序期间构造新函数,将
存储在数据结构中,并将它们作为
参数传递给其他函数和
将它们作为其他
函数的值返回。

In computer science, a programming language is said to support first-class functions (or function literal) if it treats functions as first-class objects. Specifically, this means that the language supports constructing new functions during the execution of a program, storing them in data structures, passing them as arguments to other functions, and returning them as the values of other functions.

此页面以精美的方式说明了这一点:

This page also illustrates it beautifully:


真的,就像任何其他变量一样

Really, just like any other variable




  • 函数是对象类型的实例

  • 函数可以具有属性并且具有返回其构造方法的链接

  • 您可以存储变量中的函数

  • 您可以将函数作为参数传递给另一个函数

  • 您可以从函数返回函数

    • A function is an instance of the Object type
    • A function can have properties and has a link back to its constructor method
    • You can store the function in a variable
    • You can pass the function as a parameter to another function
    • You can return the function from a function
    • 还阅读了TrayMan的评论,inte休息......

      这篇关于“头等对象”是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆