call()를 이용해서 person object의 함수 fullName을 myObject에 사용한다.
Source
<script>
var person = {
firstName:"John",
lastName: "Doe",
fullName: function() {
return this.firstName + " " + this.lastName;
}
}
var myObject = {
firstName:"Mary",
lastName: "Doe",
}
x = person.fullName.call(myObject);
document.getElementById("callDemo").innerHTML = x;
</script>
Result
This call() example uses the fullName method of person on myObject:
댓글 없음:
댓글 쓰기