What underlies this JavaScript idiom: var self = this?

前端 未结 10 2033
长情又很酷
长情又很酷 2020-11-22 03:37

I saw the following in the source for WebKit HTML 5 SQL Storage Notes Demo:

function Note() {
  var self = this;

  var note = document.createElement(\'d         


        
10条回答
  •  执念已碎
    2020-11-22 04:14

    I think the variable name 'self' should not be used this way anymore, since modern browsers provide a global variable self pointing to the global object of either a normal window or a WebWorker.

    To avoid confusion and potential conflicts, you can write var thiz = this or var that = this instead.

提交回复
热议问题