dom $$('.box')[0] を取得する必要がある関数がいくつかあります。box をグローバル変数にしたくありません。js に毎回 dom をシークさせたくありません。 . ユーザーがこれらの関数を実行していないときに $$('.box')[0] を実行したくありません。ボックス変数を保存する方法は?
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/mootools/1.4.5/mootools-yui-compressed.js"></script>
<script type="text/javascript">
/* -------
there are several function will have to get the dom $$('.box')[0] ,
I don't want to let box to be a glabal var, and I don't want to let js seek the
dom every time . and I don't want to run $$('.box')[0] when user not run these functions.
how to store the box var?
------- */
function a(){
var box = $$('.box')[0];
//...
}
function b(){
var box = $$('.box')[0];
//...
}
//...
</script>
<div class="box"></div>