私は以下のJavaScriptコードを持っています:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
<script>
function Person(first, last) {
this.first = first;
this.last = last;
}
Person.prototype.toString = function() {
return this.first + this.last;
}
var person = new Person("John", "Dough");
alert(person); // same result since alert calls toString()
</script>
</head>
<body>
</body>
</html>
問題は、なぜalert(person)
「JohnDough」が表示されるのかということです。私には、alert(person)
何も表示しないでください。