JavaScript中this关键字使用方法详解[5]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 applebbs 的 blog


    这里的this指代的是被添加原形的类的实例,和4中类定义有些相似,没有什么太特别的地方。

    6、结合2&4,说一个比较迷惑的this关键字使用:

  function jsclass()
  {
      
this.m_text = 'division element';
      
this.m_element = document.createelement('div');
      
this.m_element.innerhtml = this.m_text;
        
      
this.m_element.attachevent('onclick', this.tostring);
  }
   
  jsclass.prototype.render 
= function()
  {
      document.body.appendchild(
this.m_element);
  }     

  jsclass.prototype.tostring 
= function()
  {
      alert(
this.m_text);
  };

  
var jc = new jsclass();
  jc.render(); 
  jc.tostring();

本文关键:JavaScript中this关键字使用方法详解
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top