我在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>
Run Code Online (Sandbox Code Playgroud)
当我加载页面时,body的innerHTML是Name.protoype("function()... this.first + this.middle + this.last ...")的确切文本.我在这做错了什么?
| 归档时间: |
|
| 查看次数: |
174 次 |
| 最近记录: |