jQuery.fn.testeee = function(_msg)
{
alert(_msg);
$(this[0]).overlay({
onBeforeLoad: function()
{
alert(_msg);
}
}).load();
};
$("#popup").testeee ('test');
$("#popup").testeee ('another_test');
これは次のように表示されます。
- テスト
- テスト
- another_test
- テスト
onBeforeLoad に割り当てられた匿名関数内の alert() は、「テスト」を表示し続けます。私はこれを試します:
jQuery.fn.testeee = function(_msg)
{
alert(_msg);
$(this[0]).overlay({
onBeforeLoad: static_func(_msg)
}).load();
};
function static_func(_msg)
{
alert(_msg);
}
$("#popup").testeee ('test');
$("#popup").testeee ('another_test');
そして、それはうまく機能します。以下が表示されます。
- テスト
- テスト
- テスト
- テスト
なぜこれが起こっているのか知っている人はいますか?