Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我如何绑定“文件”;这";在IE-8 Javascript的函数体中?_Javascript_Internet Explorer 8 - Fatal编程技术网

我如何绑定“文件”;这";在IE-8 Javascript的函数体中?

我如何绑定“文件”;这";在IE-8 Javascript的函数体中?,javascript,internet-explorer-8,Javascript,Internet Explorer 8,我正在做一些跨浏览器测试。它在IE8中不可用。作为一种变通方法,我使用了一些来自Yehuda Katz的代码。他的网站建议在bind不存在时使用一个实用函数代替bind()——它在IE8中不存在 在尝试使用它时,我遇到了一个例外,它说“func.apply”。我不是在传递函数,而是在传递对象,所以apply()不存在。好的但现在我又陷入困境,回到了第一步。如何将“this”变量绑定到函数体 <snip> MyView.prototype.OnSlider_Change =

我正在做一些跨浏览器测试。它在IE8中不可用。作为一种变通方法,我使用了一些来自Yehuda Katz的代码。他的网站建议在bind不存在时使用一个实用函数代替bind()——它在IE8中不存在

在尝试使用它时,我遇到了一个例外,它说“func.apply”。我不是在传递函数,而是在传递对象,所以apply()不存在。好的但现在我又陷入困境,回到了第一步。如何将“this”变量绑定到函数体

<snip>

    MyView.prototype.OnSlider_Change = function (event, ui) {
           this.viewModel.setVariableX(ui.value * 100.0);
    }

<snip>

    $("#Slider").slider({
                   slide: (this.OnSlider_Change).bind(this),
                   change: (this.OnSlider_Change).bind(this)
           });
小结:如何将“this”变量绑定到函数体

<snip>

    MyView.prototype.OnSlider_Change = function (event, ui) {
           this.viewModel.setVariableX(ui.value * 100.0);
    }

<snip>

    $("#Slider").slider({
                   slide: (this.OnSlider_Change).bind(this),
                   change: (this.OnSlider_Change).bind(this)
           });

你刚刚把垫片的参数顺序弄错了:

       slide: bind(this.OnSlider_Change, this),
       change: bind(this.OnSlider_Change, this)

使用jquery,您可以使用实现bind方法所做工作的

$("#Slider").slider({
    slide: $.proxy(this.OnSlider_Change, this),
    change: $.proxy(this.OnSlider_Change, this)
});

Yehuda Katz不是JavaScript发明家;)他是个很酷的家伙,对JavaScript非常了解。
$("#Slider").slider({
    slide: $.proxy(this.OnSlider_Change, this),
    change: $.proxy(this.OnSlider_Change, this)
});