将 mooRainbow 转换为 mootools 1.4.4 时出现 bindWithEvent 错误
bindWithEvent error while converting mooRainbow to mootools 1.4.4
我正在尝试让mooRainbow 1.2b(http://moorainbow.woolly-sheep.net/)与mootools 1.4.4一起工作,但我遇到了一个错误,我似乎找不到答案。
本节中抛出错误...
OverlayEvents: function ()
{
var lim, curH, curW, inputs;
curH = this.snippet('curSize', 'int').h;
curW = this.snippet('curSize', 'int').w;
// $A is deprecated, the original line here was:
// inputs = $A(this.arrRGB).concat(this.arrHSB, this.hexInput);
inputs = this.arrRGB.concat(this.arrHSB, this.hexInput);
document.addEvent('click', function ()
{
if (this.visible) this.hide(this.layout);
}.bind(this));
inputs.each(function (el)
{
// this is where the error is thrown
el.addEvent('keydown', this.eventKeydown.bindWithEvent(this, el));
el.addEvent('keyup', this.eventKeyup.bindWithEvent(this, el));
}, this);
[this.element, this.layout].each(function (el)
{
el.addEvents({
'click': function (e) { new Event(e).stop(); },
'keyup': function (e)
{
e = new Event(e);
if (e.key == 'esc' && this.visible) this.hide(this.layout);
}.bind(this)
}, this);
}, this);
这是抛出的错误...
Uncaught TypeError: Object function (){
if (method.$protected && this.$caller == null)
throw new Error('The method "' + key + '" cannot be called.');
var caller = this.caller, current = this.$caller;
this.caller = current; this.$caller = wrapper;
var result = method.apply(this, arguments);
this.$caller = current; this.caller = caller;
return result;
} has no method 'bindWithEvent'
附言。这个问题似乎与MooTools/JS:bindWithEvent的问题相似,但那里的答案与我的上下文无关,我不确定它是否是同一个问题。
很久没有说话的伴侣(coda在这里)。 回到IRC!
你真的需要看看函数本身。 通常它们并不是真正的最佳选择,并且依赖于太多的参数和设置。
已弃用的绑定事件可能的解决方法可以是...
1 替换这个...
el.addEvent('keydown', this.eventKeydown.bindWithEvent(this, el));
el.addEvent('keyup', this.eventKeyup.bindWithEvent(this, el));
。像这样:
el.addEvents({
keyup: this.eventKeyup.bind(this),
keydown: this.eventKeydown.bind(this)
});
然后在 2 个事件函数中,参数 1 将是事件。 el == event.target
- 这是一种模式
2 咖喱 ftw
匿名函数中的代理。
var self = this;
el.addEvent("keyup", function(e) {
self.eventKeyup(e, this);
});
3 ...等等等等,天空是极限。
相关文章:
- Node.js v6.2.0类扩展不是函数错误
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 试图在引导模式内动态生成图表,得到offsetWidth错误
- 为什么会出现错误;未捕获的类型错误:undefined不是函数;
- 我如何修复包含在captcha的addthis中的错误
- 同样,同样的错误'ahorcado.js:26未捕获类型错误:无法读取属性'beginPath'
- 节点是否需要模块传递带有方括号的arg?这是个错误吗
- Webpack/Rect:遵循egghead.io教程,但出现错误:您可能需要一个合适的加载程序来处理此文件类型
- CKFinder 3为所选文件返回错误的URL
- 同位素库错误:未捕获错误无布局模式包装生产线8
- 铬:“;未捕获的语法错误:意外的标记:"
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- 相位器状态未捕获参考错误
- /undefined在我的404错误日志中多次出现
- Javascript未捕获语法错误意外的标识符错误
- javascript:如何在antlr生成的Lexer中进行错误处理
- Angularjs工厂注入错误
- 可以设置“;文件名"发生错误时显示的内联脚本标记的
- 将 mooRainbow 转换为 mootools 1.4.4 时出现 bindWithEvent 错误