function JSClass()
{
this.m_Text = 'division element';
this.m_Element = document.createElement('DIV');
this.m_Element.innerHTML = this.m_Text;
//第一处,下面这句的this指什么东东?
this.m_Element.attachEvent('onclick', this.ToString);
}
//第二处,这句的this指什么东东?
JSClass.prototype.Render = function()
{
document.body.appendChild(this.m_Element);
}
//第三处,这句的this指什么东东?
JSClass.prototype.ToString = function()
{
alert(this.m_Text);
};
var jc = new JSClass();
jc.Render();
jc.ToString();
它先给JSClass类加了个对象“m_Element”,是个DIV,this代表JSClass本身。第一处的This是给DIv的对象加了个Onclick的事件,表示Onclick时运行ToString事件。
第二处的This是表示运行Render方法的对象。语句作用是给JSClass加了个属性,表示JSClass的实例有个叫“Render”的方法,可以将JSClass中的“m_Element”对象加载(用AppendChild方法)到document.body的对象里。
第三处是表示运行ToString方法的对象。是对JSClass类加了第三个属性,表示在运行ToString方法时,用ALert的命令显示出“m_Text”的内容。
最后那段内容,意思是先用JSClass的类建了一个叫jc的实例,
然后运行JSClass类的Render方法,将jc实例中的DIV加载到BODY对象中。
最后Alert出jc.m_Text的内容。
文章来源:
http://songpengf117.blog.163.com/blog/static/166720520078249350938
posted @ 2008-05-11 18:58
spnet 阅读(13)
评论(0) 编辑 收藏