static 函数,为何会存在this
来源:2-23 抽象类

qq_南国雁_0
2020-02-02
static 函数,挂载在类上,为何会存在this?
写回答
5回答
-
Dell
2020-02-02
我没有用this吧?你代码截图我看下
10 -
Dell
2020-02-08
回复各位,我这快代码疏忽了,不应该用this,应该用Demo.instance,诸位改一下代码
00 -
qq_南国雁_0
提问者
2020-02-03
@dell00 -
init_center
2020-02-02
这个在Javascript和Typescript中是可以的,因为ES6中的class本身只是function的语法糖,所以:
class Demo { static getThis() { return this } } // 就是下面的语法糖写法 function Demo() { } Demo.getThis = function() { return this }
而getThis的this指向很显然就是Demo这个函数,在ES6中也就是Demo这个类本身。
012020-02-13 -
qq_南国雁_0
提问者
2020-02-02
这里的this指向的是getInstance函数,而不是demo实例吧?那么是不是不需要privade static instance?
00
相似问题