Skip to content

[构造器和操作符 "new"]中的“任何函数都可以通过 new 来运行”的描述不准确。 #876

@Nicklaus6

Description

@Nicklaus6

原文地址:https://zh.javascript.info/constructor-new#zong-jie
文中说到“任何函数都可以通过 new 来运行”。
应该是除了 箭头函数 外的所有函数,都可以通过 new 来进行。
例子:

let a = x => x + 1;
new a();
// Uncaught TypeError: a is not a constructor

因此希望能够补充考虑箭头函数的情况:
箭头函数,没有自己的this,arguments,super或 new.target, 它不能用作构造函数

Metadata

Metadata

Assignees

No one assigned

    Labels

    SolvedProblem solved

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions