2010-01-28 8 views
4

내가 자바 스크립트를 얻고있다 (prototype.js에) 오류 :예기치 않은 토큰 불법 자바 스크립트 오류

newFriend = new friend(
    response[0][email protected][0]._id, 
    response[0][email protected][0]._nickName, 
    response[0][email protected][0]._profilePicture, 
    response[0][email protected][0]._tagLine, 
    response[0][email protected][0]._isInvite, 
    response[0][email protected][0]._confirm 
); 

응답 오브젝트는 다음과 같습니다 :

[{"@type":"[Lcom.photoviewer.common.model.ThinUser;","@items":[{"_id":"000.060318.05022007.00263.0067ur","_nickName":"siraj","_country":null,"_currentStorageLimit":5000000000,"_currentStorage":0,"_currentFileCount":0,"_profilePicture":null,"_tagLine":null,"_membershipLevel":0,"_isRejected":false,"_isInvite":false,"_confirm":false,"_verifiedOn":1170716666000}]}] 
코드 줄에서 불법 예기치 않은 토큰

이것은 Chrome 브라우저 및 기타 웹킷 브라우저에서만 발생합니다. 그것은 Firefox에서 잘 작동합니다.

답변

8

대신을 시도해보십시오

newFriend = new friend(
    response[0]["@items"][0]._id, 
    response[0]["@items"][0]._nickName, 
    response[0]["@items"][0]._profilePicture, 
    response[0]["@items"][0]._tagLine, 
    response[0]["@items"][0]._isInvite, 
    response[0]["@items"][0]._confirm 
); 

내가 @ 당신에게 문제를주고있다 확신합니다.

이상한 문자의 경우 도트 표기 [email protected] 대신 ["@items"] 표기법을 사용하는 것이 더 안전합니다.

0

@과 점 표기가있는 속성 이름은 Chrome에서 호환되지 않습니다. 대신 square bracket notation을 사용하십시오 (이미 개체를 구성 할 때 수행).

+5

와우, 나는 전혀 놀랍습니다. '@'는 JS 식별자 (ECMA-262-3 외)에 허용되지 않습니다. – bobince

관련 문제