The use of “this” is confusing me in JavaScript

后端 未结 5 405
既然无缘
既然无缘 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:20

    It is very confusing. It depends on how you call the function. Doug Crockford did a good write-up in his book Javascript, the Good Parts. The gist of it is in this excellent answer to an otherwise badly formulated question.

    And no, it's not about performance.

提交回复
热议问题