2

私は次のようにjQueryを拡張しようとしています:

$.fn.extend({
    initCore:   $.fn.init,
    init:       function (selector, context, rootjQuery) {
        return $.fn.initCore(selector, context, rootjQuery);
    }
}),

ただし、正しく機能していないようで、クリック時のアラートなどの単純なものを作成するとエラーが発生します。誰でも問題を見つけることができますか?

前もって感謝します!

4

2 に答える 2

4

$.fn.initクラスコンストラクターそのものです。

あとがきを追加$.fn.init.prototype = $.fnして、元のプロトタイプを復元してみてください。

于 2012-06-21T20:56:26.330 に答える
1

私はあなたが文脈を逃していると思います。試す

return $.fn.initCore.call(this, selector, context, rootjQuery);

またはさらに簡単

return this.initCore(selector, context, rootjQuery);

いいえ、待ってください、initコンストラクター自体です。つまり、

$.fn.initCore.call(this, selector, context, rootjQuery);
doSomeThingWith(this);

...

$.fn.init.prototype = $.fn;

また

var ob = new $.fn.initCore(selector, context, rootjQuery);
doSomeThingWith(ob);
return ob;
于 2012-06-21T20:58:12.487 に答える