简体   繁体   English

功能适用于移动野生动物园

[英]Function apply in mobile safari

I'm getting a weird error message inside mobile safari on iOS: 我在iOS的移动浏览器中收到奇怪的错误消息:

"TypeError: '[object Object]' is not a valid argument for 'Function.prototype.apply'". “ TypeError:'[object Object]'不是'Function.prototype.apply'的有效参数”。

The code which triggers this works fine in Chrome (after adjusting the event type to click instead of tap). 触发此操作的代码在Chrome中运行正常(在将事件类型调整为单击而不是点击后)。

    // task-item visualization
    $(".task-item").live('touchend',function(e){
        app.toggleTask.apply(this,e);
    });

I used to have .toggleTask direct as an anonymous function inside the event binder, but I'm trying to refactor out all of this stuff so I can reuse it. 我曾经将.toggleTask直接用作事件绑定程序中的匿名函数,但是我试图将所有这些东西重构出来,以便我可以重用它。 What am I missing? 我想念什么? I'm passing this in the event context to the function with apply, but it doesn't seem to like this argument in mobile safari (guessing same error in phonegap, but can't see it). 我在事件上下文中将此参数传递给了apply函数,但它似乎不喜欢移动Safari浏览器中的此参数(猜测出phonegap中的相同错误,但看不到)。

The project is using Zepto 0.7, phonegap 1.2 and is on an iOS5 ipad. 该项目使用的是Zepto 0.7,phonegap 1.2,并且在iOS5 ipad上。

According to MDN, the apply method takes an array as the second argument. 根据MDN, apply方法将数组作为第二个参数。 You want to try: 你想尝试:

// task-item visualization
$(".task-item").live('touchend',function(e){
    app.toggleTask.apply(this,[e]);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM