wzhxhj 发表于 2013-2-7 16:07:18

关于js的prototype一个问题

今天写了一个例子,先写了一个js文件
hello.js
HelloWorld = function() {}HelloWorld.prototype =function() {   sayHello:function() {   alert ("hello");    }   sayWelcome:function() {   alert("welcome");   }}
然后在另一个htm文件中hello.html 引用这个js文件
<script type="text/javascript" src="example/hello.js"> </script><button dojoType="dijit.form.Button" id="helloButton">      Hello World!      <script type="dojo/method" event="onClick">      var hello = new HelloWorld();               hello.sayHello();               </script>   </button>
这样做,会报一个错误,"hello未定义"
所以我js改动一下
今天写了一个例子,先写了一个js文件
hello.js
function HelloWorld() {}HelloWorld.prototype.sayHello =function() {      alert ("hello");    }
这样就能通过,现在还不知道什么原因。
页: [1]
查看完整版本: 关于js的prototype一个问题