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) 디스플레이 완료
무엇이 질문입니까? –
출력은 * 무엇입니까? 그게 뭐야? "추가 디스플레이 라인이 표시되는 것을 보는 것"은 무엇을 의미합니까? – h2ooooooo
'fullname' 함수는'undefined'를 리턴합니다. 'console.log (x.fullname())'는 리턴 값을 기록합니다. – apsillers