1

我正在尝试让 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但那里的答案与我的上下文无关,我不确定它是否是同一个问题。

4

1 回答 1

0

好久没说话了(这里是尾声)。回到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咖喱ftw

匿名函数中的代理。

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

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

于 2012-04-12T20:49:19.340 回答