gpt4 book ai didi

javascript - 将 mooRainbow 转换为 mootools 1.4.4 时出现 bindWithEvent 错误

转载 作者:行者123 更新时间:2023-11-28 09:55:29 26 4
gpt4 key购买 nike

我正在尝试让 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'
PS。该问题似乎与此处的问题类似 MooTools/JS: bindWithEvent但那里的答案与我的上下文无关,我不确定这是否是同一个问题。

最佳答案

好久没说话了,伙计(这里是尾声)。返回 IRC!

你确实需要看看函数本身。通常它们并不是真正最优的,并且依赖于太多的参数和设置。

已弃用的bindWithEvent的可能解决方法是...

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 curry ftw

匿名函数中的代理。

var self = this;
el.addEvent("keyup", function(e) {
self.eventKeyup(e, this);
});

3 ...等等等等。天空是极限。

关于javascript - 将 mooRainbow 转换为 mootools 1.4.4 时出现 bindWithEvent 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10130708/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com