自己実行関数に含まれる jQuery 拡張機能を作成しています。
(function($) {
// global variables for the purposes of this test
__$ = $;
__$support = $.support;
$.support.abc = "123";
// Setup for my extension goes here.
})(jQuery);
私のテストページには、
<script type="text/javascript" src="jquery-1.5.2.js"></script>
<script type="text/javascript" src="myplugin.js"></script>
<script type="text/javascript">
$(function() {
console.log(__$ === $); // false
console.log(__$support === $.support); // false
console.log($.support.abc); // undefined
});
</script>
なぜこれが起こるのですか?jQuery
オブジェクトを上書きする可能性のあるスクリプトや jQuery プラグインは他にありません。
jQuery
ドキュメントの準備ができた後、jQuery ソース自体のどのコードがオブジェクトを上書きするかを見つけることができませんでした。何か案は?
jQuery.support
これを回避する方法がない場合、ドキュメントの準備ができた後もアクセスできるオブジェクトに新しいプロパティを定義するための正しい手順は何でしょうか?
編集: jQuery ソースを誤って再評価したテスト コードの重要な部分を省略し、この問題が発生した理由を説明しました。以下の私の答えを見てください。