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);
}
안녕하세요,이 카드 클래스는 매개 변수로 두 가지 다른 객체를 가져옵니다. 그 중 하나는 'width'라는 속성이 포함 된 styleAttr입니다. 이 객체를 constructCard에 전달하지 않으면 styleAttr.width 속성에 액세스 할 수 없습니다. 위의 예제가 작동합니다. 그러나 나는 할 경우이 :메서드 내에서 자바 스크립트 객체 속성에 액세스
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 구문에 가깝기 때문에 선호합니다. –