我在JavaScript中練習面向對象的語法,並遇到一些問題。這是我的代碼:關於面向對象的混淆javascript
<html>
<head>
<script type="text/javascript">
function Name(first,mid,last) {
this.first = first;
this.middle = mid;
this.last = last;
}
Name.prototype.fullname = function() {
return this.first + " " + this.middle + " " + this.last;
}
Name.prototype.fullnamereversed = function() {
return this.last + " " + this.middle + " " + this.first;
}
var s = new Name("James","Harlow","Smith")
</script>
</head>
<body>
<script type="text/javascript">
document.body.innerHTML = s.fullname;
document.body.innerHTML = s.fullnamereversed;
</script>
</body>
</html>
當網頁加載完畢後,身體的innerHTML是Name.protoype的確切文本(「功能()... this.first + this.middle + this.last ......「)。我在這裏做錯了什麼?
我的部分愚蠢的錯誤。謝謝。 – dopatraman