How to handle lack of JavaScript Object.bind() method in IE 8

前端 未结 4 2188
长情又很酷
长情又很酷 2020-11-27 07:13

I am writing a bit of JavaScript that uses the Object.bind method.

funcabc = function(x, y, z){ 
    this.myx = x;
    this.playUB = function(w)         


        
4条回答
  •  我在风中等你
    2020-11-27 07:31

    The Function constructor is the old-fashioned way of doing this:

    var foo = function(x,y,z){ return Function("x,y,z","return Math.max.call(this, x, y, z)")(x,y,z) }
     
    var bar = function(x,y,z){ return Function("x,y,z","return Math.min.call(this, x, y, z)")(x,y,z) }
     
    console.log(foo(1,2,3) );
     
    console.log(bar(3,2,1) );

    References

    • Functional JavaScript: Harnessing the power of the Function Object
    • eval() isn’t evil, just misunderstood
    • [Scope] of Functions Created via the Function constructor
    • John Resig - Fast JavaScript Max/Min

提交回复
热议问题