我在下面有这个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)
不应该显示任何东西。