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-それは1つのパターンです

2カレーftw

anon関数のプロキシ。

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

3...など空は限界です。

于 2012-04-12T20:49:19.340 に答える