访问Javascript原型函数 [英] Accessing a Javascript prototype function

查看:105
本文介绍了访问Javascript原型函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个原型函数,如event。

原型

<$ p
alert(适用于输入中的键控!);
}
$ b Func.prototype = {
keyup:function(func){
//使用func
}添加事件侦听器和回调函数,
event:function(e ,func){
//在这里做什么来调用函数keyup
}
};

原型名称在变量 e 中。但是我怎样才能调用函数使用变量名称?



我这样做,以便传递keyup keydown将添加keyup和keydown侦听器,这比调用每个原型函数更好。



谢谢。

解决方案最好的方式来达到这个目的是:

  events:function(events,func){
这[事件](FUNC);




$ b

感谢 CrazyTrain code>,正如他在评论中提到的那样。


I have a prototype function such as event.

Prototype

Func("input_element_id").event("keyup",function(){
    alert("Works on keyup in an Input!");
}

Func.prototype= {
    keyup: function(func){
         //adding event listener and callback using func
    },
    event: function(e,func) {
         //what to do here to call function "keyup"
    }
};

The prototype name is in the variable e. But how can i call that function using the variable name?

I am doing this, so that passing "keyup keydown" will add keyup and keydown listeners, which is better than calling each prototype function individually.

Thanks.

解决方案

The best way to achieve this is by:

events: function(events,func) {
            this[events](func);
        }
    }

Thanks to CrazyTrain, As he mentioned in Comments.

这篇关于访问Javascript原型函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆