重複の可能性:
オブジェクト内の「this」
私が取り組んでいるjQueryプラグインのいくつかのデフォルトオプションのオブジェクトリテラルを作成しようとしています:
var defaults = {
r: 5,
top: this.r,
bottom: this.r,
topleft: this.top,
topright: this.top,
bottomleft: this.bottom,
bottomright: this.bottom
};
私が参照するときdefaults.top
それはundefined
この仕事をするために私にできることは何ですか?それとも別のアプローチですか?オブジェクトリテラルである必要があります。
追加した:
それは(default
オブジェクト)であり、あなたが見ることができるようにそれがカスケードダウンする方法は、速記のテクニックのようなものであることが意図されていました。たとえば、すべてのコーナーを同じに定義し{r: 5}
たい場合はを使用しますが、上部と下部を{top: 5, bottom: 1}
再び異なるものにしたい場合は、個別{topleft: 5, topright:2, bottomleft: 3, bottomright:19 }
にこれを明確にしないことをお詫びしますが、ご回答いただきありがとうございます。
答え:これは私がやったことです
if(o.topleft == undefined || o.topright == undefined || o.bottomleft == undefined || o.bottomright == undefined){
if(o.top == undefined || o.bottom == undefined){
if(o.r == undefined){
o.topleft = 5;
o.topright = 5;
o.bottomleft = 5;
o.bottomright = 5;
}else{
o.topleft = o.r;
o.topright = o.r;
o.bottomleft = o.r;
o.bottomright = o.r;
}
}
else{
o.topleft = o.top;
o.topright = o.top;
o.bottomleft = o.bottom;
o.bottomright = o.bottom;
}
}
夕食はずさんですが、ちょっとうまくいきました!助けてくれてありがとう!その説明が私にこのようにそれをするように導いたので、私は答えを選びました!