2013-11-26 3 views
-4

2 개의 속성과 fullname이라는 함수가있는 객체를 정의했습니다. fullname 함수를 호출하면 표시되는 추가 행이 표시됩니다.Javascript 객체의 함수 호출

<html> 
    <head> 
     <script> 
      function person(firstname,lastname){ 
       this.firstname = firstname; 
       this.lastname = lastname; 
       var id = 1; 
       this.fullname = function(){ 
       console.log("firstname = " + firstname + " lastname = " + lastname);  
       } 
      } 

      x = new person("Bob","McDonald"); 
      console.log(x.firstname); 
      console.log(x.fullname()); 
      console.log("Display finish"); 

     </script> 
    </head> 
    <body> 
     This is the body 
    </body> 
</html> 

출력 firebug-


basics.html (라인 14) FIRSTNAME = 밥 LASTNAME = 맥도날드
basics.html (라인 9) 미정
basics.html (라인으로부터 15) 디스플레이 완료

+1

무엇이 질문입니까? –

+4

출력은 * 무엇입니까? 그게 뭐야? "추가 디스플레이 라인이 표시되는 것을 보는 것"은 무엇을 의미합니까? – h2ooooooo

+0

'fullname' 함수는'undefined'를 리턴합니다. 'console.log (x.fullname())'는 리턴 값을 기록합니다. – apsillers

답변

1

사용자의 fullname 기능은 이미 콘솔에 로그인되어 있고 아무것도 표시하지 않습니다. 지. 당신은 단순히 그것을 부를 필요가 있습니다.

console.log(x.firstname); 
x.fullname(); //no console.log 
console.log("Display finish"); 
+0

예, thats는 문제가 .. 감사합니다. – user1050619