関数がの前と外で定義されている場合、キャッシュされた jQuery 参照をコールバックとして関数に渡すための推奨される方法は$domContainer
何var $domContainer = $('#container');
ですか$(document).ready()
?
例:
<script src="/plugins.js"></script>
この再利用可能な関数の外部ファイルで
function rowAction ( event ) { // how do I get context here?
// how can I access $domTable and $domFilters
// I can access $(event.target) and traverse the dom
// back to $domTable, but $domTable is not defined
// in the external file, although a reference is cached
// in the local scope of $(document).ready();
// likewise, $domTable could be accessed through event.delegateTarget
// however, how can I pass $domFilters, and other vars?
}
メインスクリプトでは
<script src="/scripts.js"></script>
標準ドキュメントの準備
$(document).ready(function(){
// Cached References
var $domFilters = $('#form .filter'), // more than 1 reference returned
$domTable = $('#results'); // 1 reference returned
$domTable.on('click','.menu',rowAction);// reference function in plugins.js
// how do I pass $domFilters to rowAction to avoid dom lookups?
// I could pass $domFilters to a plugin like $(...).plugin({f:$domFilters});
// if it had optional arguments, but if it's not a plugin, what's the
// equivalent way to do it?
});
これにアプローチする方法は、インライン関数を使用してコールバック関数名をラップすることですか?
標準的な慣行へのポインタも大歓迎です。