function Card(styleAttr, cardInfo)
{
//Attributes
this.styleAttr = styleAttr;
this.cardInfo = cardInfo;
//Functions
constructCard(this.styleAttr);
}
function constructCard(styleAttr) {
var cardCSS = {
'width':styleAttr.width,
'height':styleAttr.height,
'background-color':'black'
}
$('<div class="Card"></div>').appendTo('body').css(cardCSS);
}
こんにちは、このカードクラスは、他の2つのオブジェクトをパラメータとして取得します。それらの1つはstyleAttrで、 'width'という名前のプロパティが含まれています。このオブジェクトをconstructCardに渡さない限り、styleAttr.widthプロパティにアクセスすることはできません。上の例は動作します。しかし、私はやる場合は、この:メソッド内でJavascriptオブジェクトの属性にアクセスする
function constructCard() {
var cardCSS = {
'width': this.styleAttr.width, //Undefined
'height':styleAttr.height,
'background-color':'black'
}
$('<div class="Card"></div>').appendTo('body').css(cardCSS);
}
私は、わからないんだけど、私はそれがプロパティのアクセスできるようにするには、クラスへの関数constructCardをバインドしなければならないのか、私が通過するように強制していますので、他の言語のほとんどのコードオブジェクトは値を取得します。あるいは、グローバル変数にする必要がありますか?
私はMoz Docからキャッチしなかった単純なものでなければなりません。
おかげ
お互いに、これはCの構文に近いので、私はそれを好む。 –