여기에는 카드와 카드로 된 두 개의 "클래스"가 있습니다. 값을 소송을 잡고 합치 문자열을 출력하기 위해 사용되는 오브젝트왜이 자바 스크립트가 실행되지 않습니까?
- 추가 카드
- 제거 카드
- 종류 및
카드를 셔플한다 : 카드는 본질적으로 구체적인 방법과 배열입니다 양자 모두.
여기 내 문제는이 코드를 실행하려고 시도하는 것입니다. 즉, 버튼 클릭으로 setup()
입니다. 카드를 만들 때 카드가 계속 실행됩니다. 나는 출력이 여전히 hello world로 바뀌기 때문에 이것을 안다.
하지만 카드를 카드 클래스 또는 데크에 추가하려고합니다. 스크립트가 실행을 중지합니다. 왜 이런지 모르겠지만 Array를 사용하는 방법이 마음에 들지 않습니다.
그 중 하나가 질문입니다.
내 두 번째 질문은 내가
var temp= new card('c','2');
alert(temp.getvalue());
이 또한 실패 할 때.
내가 잘못한 부분에 대한 통찰력은 도움이되고 감사 할 것입니다.
this.getvalue = function() {
return (suit.toString() + value.toString());
};
당신이 양복과 값에 액세스해야합니다 :
function setup() {
var temp = new card('c', '2');
var textbox = document.getElementById("output");
textbox.value = "Hello, world!";
};
Array.prototype.shuffle = function() {
for (var i = this.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var tmp = this[i];
this[i] = this[j];
this[j] = tmp;
}
return this;
}
function card(s, v) {
this.suit = s;
this.value = v;
this.getvalue = function() {
return (suit.toString() + value.toString());
};
this.getSortOrder = function() {
var factor;
if (this.suit == 'c') {
factor = 0;
}
else if (this.suit == 'd') {
factor = 1;
}
else if (this.suit == 'h') {
factor = 2;
}
else if (this.suit == 's') {
factor = 3;
}
else {
factor = -2;
}
return (this.value + 13 * factor);
};
};
function Cards() {
this.list = new Array();
this.Addcard = function (c) {
list.push(c);
};
this.removeCard = function (c) {
list.splice(list.indexOf(c), 1);
};
this.lookat = function (i) {
return list[i];
};
this.sort = function() {
list.sort();
};
this.shuffle = function() {
list.shuffle();
};
this.prototype;
};
자바 스크립트 개발 콘솔에서 오류가 발생합니까? – Matt
질문 당 하나의 질문을주십시오. – 0x499602D2
Stackoverlow 사용자는 디버거가 아닙니다. – gdoron