mozilla
您的搜索结果

    JavaScript参考文档

    关于此参考

    该JavaScript参考提供Javascript语言的知识仓库. 详细的描述了完整的Javascript语言的信息. 如果你编写JavaScript代码, 你会经常使用这些也页面 (因此标题为 "JavaScript reference"). 如果你正在学习JavaScript, 或血药帮助理解一些Javascript的功能或特性, 请查看 JavaScript guide.

    JavaScript 语言正带算在更大的环境中使用,如浏览器,服务端脚本,或类似中. 大多数情况下, 该参考试的内容试图保证与目标浏览器环境无关.

    哪里查找 JavaScript 信息

    JavaScript 核心语言特性的文档 (绝大部分基于 ECMAScript ) 包含如下:

    如果你是Javascript新手,从guide开始. 当你有一定基础后, 可以开始使用reference 获取单个对象和语言构造的详情.

    该参考的结构

    JavaScript参考中你能发现如下的章节:

    标准内置对象
    该章节描述了所有的JavaScript标准内置对象, 及相关的方法和属性.
    语句和声明
    JavaScript应用由合适的语法的语句构成. 单条语句可以占用多行.多条语句也可能只占用一行,中间用分好分隔. 语句不是只有一个关键词,而是由一组关键词组成.
    表达式和运算符
    该章节描述了所有的JavaScript 操作符运算符, 表达式和关键词.
    函数
    JavaScript 函数的章节.
    JavaScript更新
    JavaScript 版本历史的章节.

    更多参考页面

    全局对象

    函数与函数作用域

    语句

    JavaScript applications consist of statements with an appropriate syntax. A single statement may span multiple lines. Multiple statements may occur on a single line if each statement is separated by a semicolon. This isn't a keyword, but a group of keywords.

    Statements and declarations by category

    For an alphabetical listing see the sidebar on the left.

    Control flow

    Block
    A block statement is used to group zero or more statements. The block is delimited by a pair of curly brackets.
    break
    Terminates the current loop, switch, or label statement and transfers program control to the statement following the terminated statement.
    continue
    Terminates execution of the statements in the current iteration of the current or labeled loop, and continues execution of the loop with the next iteration.
    Empty
    An empty statement is used to provide no statement, although the JavaScript syntax would expect one.
    if...else
    Executes a statement if a specified condition is true. If the condition is false, another statement can be executed.
    switch
    Evaluates an expression, matching the expression's value to a case clause, and executes statements associated with that case.
    throw
    Throws a user-defined exception.
    try...catch
    Marks a block of statements to try, and specifies a response, should an exception be thrown.

    Declarations

    var
    Declares a variable, optionally initializing it to a value.
    let
    Declares a block scope local variable, optionally initializing it to a value.
    const
    Declares a read-only named constant.

    Functions and classes

    function
    Declares a function with the specified parameters.
    function*
    Generators functions enable writing iterators more easily.
    return
    Specifies the value to be returned by a function.
    class
    Declares a class.

    Iterations

    do...while
    Creates a loop that executes a specified statement until the test condition evaluates to false. The condition is evaluated after executing the statement, resulting in the specified statement executing at least once.
    for
    Creates a loop that consists of three optional expressions, enclosed in parentheses and separated by semicolons, followed by a statement executed in the loop.
    for each...in
    Iterates a specified variable over all values of object's properties. For each distinct property, a specified statement is executed.
    for...in
    Iterates over the enumerable properties of an object, in arbitrary order. For each distinct property, statements can be executed.
    for...of
    Iterates over iterable objects (including arrays, array-like objects, iterators and generators), invoking a custom iteration hook with statements to be executed for the value of each distinct property.
    while
    Creates a loop that executes a specified statement as long as the test condition evaluates to true. The condition is evaluated before executing the statement.

    Others

    debugger
    Invokes any available debugging functionality. If no debugging functionality is available, this statement has no effect.
    export
    Used to export functions to make them available for imports in external modules, another scripts.
    import
    Used to import functions exported from an external module, another script.
    label
    Provides a statement with an identifier that you can refer to using a break or continue statement.
    with
    Extends the scope chain for a statement.

    Specifications

    Specification Status Comment
    ECMAScript 1st Edition. Standard Initial definition.
    ECMAScript 5.1 (ECMA-262)
    Statements
    Standard
    ECMAScript 6 (ECMA-262)
    ECMAScript Language: Statements and Declarations
    Release Candidate New: function*, let, for...of, yield, class

    See also

    操作符与其他关键字


    该章节说明了Javascript语言所有的运算符,表达式和关键字.

    表达式和运算符分类

    左侧工具栏是按字母表排序的列表.

    主要表达式

    JavaScript中基本关键字和常用表达式.

    this
    this 关键字指向函数的执行上下文.
    function
    function 关键字定义了函数表达式.
    function*
    function* 关键字定义了一个 generator 函数表达式.
    yield
    暂停和恢复 generator 函数
    yield*
    委派给另外一个generator函数或可迭代的对象.
    []
    数组初始化/字面量语法.
    {}
    对象初始化/字面量语法.
    /ab+c/i
    正则表达式字面量语法.
    [for (x of y) x]
    Array comprehensions.
    (for (x of y) y)
    Generator comprehensions.
    ( )
    圆括号操作符.

    Left-hand-side expressions

    Left values are the destination of an assignment.

    Property accessors
    成员访问可以访问对象的属性或方法
    (object.property and object["property"]).
    new
    new 运算符创建了构造函数实例.
    super
    super 关键字调用父类的构造器.
    ...obj
    The spread operator allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) are expected.

    自增运算和自减运算

    前置/后置自增运算符和前置/后置自减运算符.

    A++
    后置自增运算符.
    A--
    后置自减运算符.
    ++A
    前置自增运算符.
    --A
    前置自减运算符.

    一元运算符

    一元运算符只有一个操作数.

    delete
    delete 运算符用来删除对象的属性.
    void
    void 运算符表示表达式放弃返回值.
    typeof
    typeof 运算符用来判断给定对象的类型.
    +
    一元加运算符将操作转换为Number类型.
    -
    一元减运算符将操作转换为Number类型并取反.
    ~
    按位非运算符.
    !
    逻辑非运算符.

    Arithmetic operators

    Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value.

    +
    加法运算符.
    -
    减法运算符.
    /
    除法运算符.
    *
    乘法运算符.
    %
    取模运算符.

    关系运算符

    A comparison operator compares its operands and returns a Boolean value based on whether the comparison is true.

    in
    in运算符用来判断对象是否拥有给定属性.
    instanceof
    instanceof 运算符判断一个对象是否是另一个对象的实例.
    <
    小于运算符
    >
    大于运算符.
    <=
    小于等于运算符.
    >=
    大于等于运算符.

     

    The result of evaluating an equality operator is always of type Boolean based on whether the comparison is true.

    ==
    相等 运算符.
    !=
    不等 运算符.
    ===
    全等 运算符.
    !==
    非全等 运算符.

    位移运算符

    Operations to shift all bits of the operand.

    <<
    Bitwise left shift operator.
    >>
    Bitwise right shift operator.
    >>>
    Bitwise unsigned right shift operator.

    二元按位运算符

    Bitwise operators treat their operands as a set of 32 bits (zeros and ones) and return standard JavaScript numerical values.

    &
    Bitwise AND.
    |
    Bitwise OR.
    ^
    Bitwise XOR.

    二元逻辑运算符

    逻辑运算符是典型的使用boolean(逻辑)值, and when they are, they return a boolean value.

    &&
    逻辑与.
    ||
    逻辑或.

    Conditional (ternary) operator

    (condition ? ifTrue : ifFalse)

    The conditional operator returns one of two values based on the logical value of the condition.

    Assignment operators

    An assignment operator assigns a value to its left operand based on the value of its right operand.

    =
    Assignment operator.
    *=
    Multiplication assignment.
    /=
    Division assignment.
    %=
    Remainder assignment.
    +=
    Addition assignment.
    -=
    Subtraction assignment
    <<=
    Left shift assignment.
    >>=
    Right shift assignment.
    >>>=
    Unsigned right shift assignment.
    &=
    Bitwise AND assignment.
    ^=
    Bitwise XOR assignment.
    |=
    Bitwise OR assignment.
    [a, b] = [1, 2]
    {a, b} = {a:1, b:2}

    Destructuring assignment allows you to assign the properties of an array or object to variables using syntax that looks similar to array or object literals.

    逗号操作符

    ,
    The comma operator allows multiple expressions to be evaluated in a single statement and returns the result of the last expression.

    非标准化特性

    Legacy generator function
    The function keyword can be used to define a legacy generator function inside an expression. To make the function a legacy generator, the function body should contains at least one yield expression.
    Expression closures
    The expression closure syntax is a shorthand for writing simple function.

    规范

    Specification Status Comment
    ECMAScript 1st Edition. Standard Initial definition.
    ECMAScript 5.1 (ECMA-262)
    Expressions
    Standard  
    ECMAScript 6 (ECMA-262)
    ECMAScript Language: Expressions
    Release Candidate New: Spread operator, destructuring assignment, super keyword, Array comprehensions, Generator comprehensions

    相关链接

    运算符优先级

    注释

    E4X (扩展)

    全局语句:

    全局函数:

    全局构造函数:

    附录一 - 保留关键词

    附录二 - 过时的功能

    文档标签和贡献者

    此页面的贡献者有: ziyunfei, kovchou, CHiENiUS, teoli
    最后编辑者: teoli,
    隐藏侧边栏