"Functions in JavaScript are the first class of objects (first-class object)"

Source: Internet
Author: User

In itself this sentence is very good explanation, the function has two main characteristics, quoted from the Chen Xin translation of "javascript mode":

1. The function is the first class of objects:

  • Functions can be created dynamically at run time, and can also be created during program execution.
  • Functions can be assigned variables, they can be copied to other variables, can be extended, in addition, except for a few special cases, functions can also be deleted.
  • Can be passed as a parameter to other functions, and other functions can also be returned.
  • Functions can have their own properties and methods.

2. The function provides scope

In JavaScript, you do not use the curly brace {} syntax to define the scope of a local variable, that is, the block does not create a scope. This also means that the variables declared in the If or for expressions will leapfrog the petition. So in order to prevent namespace pollution, self-executing anonymous functions are very much the way.


In StackOverflow http://stackoverflow.com/questions/245192/what-are-first-class-objects

Translate as follows:

Simply put, the first class of objects means that there is no difference between using and other objects.

A first class object is an entity that can be dynamically created, destroyed, passed, returned, and has the same status as other variables in the programming language.

The first class of objects has the following characteristics:

An anonymous literal is treated as an expression.

Can be stored in variables.

Can be stored in the data structure.

has a unique identity (can be distinguished by a function name)

Ability to perform the same comparison with other entities

can be used as parameters

Can be treated as a return value

Ability to dynamically create at run time

can print

Can read

Can be passed in different processes

Can be stored outside of the running process

"Functions in JavaScript are the first class of objects (first-class object)"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.