Confusing JavaScript statement: “var x = new this();”

后端 未结 8 1042
野趣味
野趣味 2021-02-01 20:30

I thought I understood the concept of the JavaScript prototype object, as well as [[proto]] until I saw a few posts regarding class inheritance.

Firstly, \"JavaScript OO

8条回答
  •  北荒
    北荒 (楼主)
    2021-02-01 20:38

    "this" means the context of the function currently running.

    The code you are posting surely appears in a function that act as a method for an object. So the object is the context of the function.

    "new this()" will return a clone of the current object after running its constructor function with the passed arguments.

提交回复
热议问题