What does “self” mean in javascript?

前端 未结 5 1847
-上瘾入骨i
-上瘾入骨i 2020-12-02 23:04

I read here that \"self Refers to the current window or form\".

Self does not seem to refer to the current form in this case:

5条回答
  •  爱一瞬间的悲伤
    2020-12-02 23:47

    Never, unless I wanted to create a self variable in the scope of a function referring to the context for later reference,

    function Constructor() {
        var self = this;
    }
    

    You should use this to refer to the element at hand, not self. In global scope though this is a reference to window, and self is also window.

提交回复
热议问题