Javascript Named Function Expressions in Internet Explorer

后端 未结 2 971
不思量自难忘°
不思量自难忘° 2020-12-09 23:33

Why does the following code not work in Internet Explorer (I\'ve only tested in IE8 so far):

(function(){
  this.foo = function foo(){};

  foo.prototype = {         


        
2条回答
  •  醉话见心
    2020-12-09 23:58

    IE has a lot of problems with named function expressions. As you said in your question, stick with this:

    this.foo = function (){};
    

    For an in-depth, grueling read on this topic, check out this link

    The short of it is that the inner, named function expression is treated as a function declaration, and hoisted up to places it should never, ever be.

提交回复
热议问题