“ this”指的是方法调用内的窗口

时间:2018-10-01 18:00:45

标签: javascript oop iife

我对此深感困惑;

(function(win) {

   const Thing = function(imADiv) {
    this.test = imADiv;
   };

   Thing.prototype = {
      self: this
   };

   win.Thing = Thing;

})(window);

const thingy = new Thing(document.getElementById('test'));
console.log(thingy.self());

在这种情况下,this为什么为了上帝的爱而返回窗口对象?

0 个答案:

没有答案