关于面向对象的javascript的困惑

dop*_*man 2 javascript oop

我在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 ...")的确切文本.我在这做错了什么?

Ruy*_*iaz 5

您需要使用()运算符调用函数:

document.body.innerHtml = s.fullname();
Run Code Online (Sandbox Code Playgroud)