背景: Zen カートの水平ポップアウト メニューを編集して、ポップアウトをメニュー内でインラインで開くようにしようとしています。私が抱えている問題は、付属の javascript/jquery を理解するのに苦労していることです。
全体を投稿しないと、コードの構造は次のようになります。
(declare some vars)
//some functions like this:
function funcname(obj) {
//do something
}
//then one big master function like this:
function bigfunc(arg1, arg2, arg3, arg4, arg5) {
//declare some vars based on this
this.varname1=varname1;
this.varname2=varname2;
//declare some functions inside the big function
this.innerfunc1= function() {
//do stuff
}
this.innerfunc2= function() {
//do stuff
}
}//end of big function
//then goes on to declare init function
function initfunc(){
//this creates new bigfunc(arg1 arg2 arg3...) for each main menu item
}
//finally calls init function with
window.onload = initfunc();
さて、私の混乱に移りましょう -
1) まず明確にするために、bigfunc() に浮かんでいるすべての this と、これがオブジェクトを作成している new bigfunc() で呼び出されるという事実に基づいて、私は正しいと思いますか?
2)私の現在の問題は、bigfunc() 内の次のような関数の 1 つにあります。
this.slideChildMenu = function() {
var divref = this.children[0].div;
var ulref = this.children[0].ul;
var maxwidth = this.children[0].width;
var nextWidth;
if (this.isMouseOnMe || this.isMouseOnChild()) {
nextWidth = divref.offsetWidth + slideSpeed_out;
if (nextWidth >= maxwidth) {
this.finishOpeningChild(divref, ulref, maxwidth);
} else {
ulref.style.left = nextWidth - maxwidth + "px";
divref.style.width = nextWidth + "px";
setTimeout("slideChildMenu('" + this.getId() + "')", slideTimeout_out);
}
}
今私の計画は、これを変更してjquery showを使用して要素を開くことなので、これを試しました:
this.slideChildMenu = function() {
var divref = this.children[0].div;
var ulref = this.children[0].ul;
if (this.isMouseOnMe || this.isMouseOnChild()) {
$(divref).show(function(){
this.finishOpeningChild(divref, ulref);
});
}
}
しかし、私はこれを取得しています-> TypeError: this.finishOpeningChild is not a function
さて、この js では他にも多くのことが行われているので、ここにいる誰かに私の仕事を依頼することは夢にも思いませんが、誰かがこの関数が関数ではない理由を説明してくれることを願っています。残りを解決することができます。
注: これは "this" のスコープに関係していると思いましたが、this の値は両方のバージョンのコードでまったく同じように見えます。
これが長いものであることは承知していますが、あなたの助けに感謝します。