The use of “this” is confusing me in JavaScript

后端 未结 5 396
既然无缘
既然无缘 2020-12-04 13:38

Working with the JavaScript one of the confusing thing is when using this

var x = {  
  ele : \'test\',
  init : function(){ 
    alert(this.ele)         


        
5条回答
  •  失恋的感觉
    2020-12-04 14:00

    To me, it helped a lot the following guideline: every time you see this think owner. The object who owns the variable name to which the function is assigned will become the this. If you cannot make sense to who owns it, then this will be window.

提交回复
热议问题