코드가 그 나는 왜 나에게 오류를주는 것 this.bar 하나 개의 속성으로 우우의 단순한 객체를 생성 할 왜이 자바 스크립트 코드에 오류가 있습니까?
Boo.prototype.initone (a) { <-- Syntax error
코드
의이 라인에? 이 오류는 아래에 나와 있는데, 이는 잡히지 않은 구문 오류이지만 표시되지 않습니다.구문 오류는 게시해서는 안되지만 아래 코드에서 완전히 잘못된 것을 보지 못했습니다. 여기
오류 코드 :
Boo.prototype.initone (a) {
this.bar = a;
return this;
}
오류
Uncaught SyntaxError: Unexpected token {
코드 :
<script>
function Test1() {
}
function Boo() {
this.bar = 'Test This Method';
}
Boo.prototype.initone (a) {
this.bar = a;
return this;
}
Boo.prototype.inittwo (b) {
this.bar = 'something to do with ' + b;
return this;
}
var a = new Boo().initone('constructor 1');
var b = new Boo().inittwo('constructor 2');
</script>
코드 : 여전히 캐치되지 않는 예외를 표시합니다이 코드. 내가 이것을 돌려 주면 initone에 에러가 발생하지 않지만 inittwo는 괜찮은 것 같습니다. 자바 스크립트는 당신이 원하는 무엇을 모르기 때문에
Boo.prototype.initone = function (a) {
this.bar = a;
return this;
}
Boo.prototype.inittwo = function (b) {
this.bar = 'something to do with ' + b;
return this;
}
가'Boo.prototype.initone = 기능을 확인 (A) {' –
당신이'Boo.prototype.initone의 (a) {}'함수를 정의하는 것 무엇을 생각하게? –
업데이트 된 코드가 SyntaxError를 throw하지 않습니다. 그렇다면 코드 외부에 다른 문제가 있습니다. 아니면 다른 오류입니까? strict 모드에 있다면'this'의 값은'null' 또는'undefined'가 될 수 있습니다. 그러면 TypeError가 발생합니다. –