jQueryオブジェクトのスタックを別のjQueryオブジェクトにコピーして、end
まったく関係のないオブジェクトを返す場合でもプラグインで使用できるようにするにはどうすればよいですか?例:
$(myselector)
.next() // Destructive operation
.doSomething()
.end() // Goes back to "myselector"
.doSomethingElse(); // Works fine!
$.fn.myPlugin = function() {
return $(unrelated); // No stack, can't call "end" on it
};
$(myselector)
.myPlugin() // Destructive operation
.doSomething()
.end() // Goes back to nowhere, since the stack is empty
.doSomethingElse(); // Doesn't work
のスタック$(unrelated)
を含むようにオブジェクトを変更したいので、2番目の例が機能します。これがjsFiddlethis
の完全な例です。