用js实现一个类,怎样在类的方法内调用alert函数?好像不能直接调用alert呀。//js
function myTree(objName, strImgPath) {
  this.name = objName;
  this.imgSrc = strImgPath;
}myTree.prototype.show = function(msg) {
 //此处怎样调用alert函数?
}

解决方案 »

  1.   

    首先把 实现一个类的 说法不准确只能说你 定义了一个 function类型的对象 然后在给他定义了一个原型方法不能直接调用alert 可能是这个show 没有被正确调用 或者执行
    function myTree(objName, strImgPath) {
      this.name = objName;
      this.imgSrc = strImgPath;
    }myTree.prototype.show = function(msg) {
      alert(msg);
      window.alert(this.name);
    }
    var mt=new myTree('kk','kk1');
    mt.show('msg');
      

  2.   


    我也用window.alert(msg);做了
    myTree.prototype.show = function(msg) {
     window.alert(msg);
    }myTree.prototype.open = function() {
     this.alert("open begin");
    }调用对象的open方法,但是没有弹出消息框。
      

  3.   

    ... 你用错方法了吧 应该是this.show
      

  4.   


    myTree.prototype.open = function() {
     this.show("open begin");
    }
    我改成了this.show也没反应。
    我的这些代码放在一个js文件里面,服务用的jboss,修改js文件,怎么才能重新反映到画面应用中?
      

  5.   

    myTree.prototype.show = function(msg) {
      alert(msg);
      window.alert(this.name);
    }
      

  6.   

    单独测试已经OK了。我的问题原因是在我的开发环境中(eclipse+jboss3.2.2)
    ,修改了js文件,重新启动服务,并且把浏览器中的缓存删除掉,
    修改的js代码没有反应。