<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template</title>
<style type="text/css">
/* <![CDATA[ *//* ]]> */
</style>
<script type="text/javascript">
/*<![CDATA[*/
if (navigator.appName=="Microsoft Internet Explorer")
{
//最大化窗口
self.moveTo(-5,-5)
self.resizeTo(screen.availWidth +8,screen.availHeight+8)
//这个脚本定义的宽度其实比原窗口还要大那么一点.
}
/*]]*/
</script>
<script language="javascript">
function myObject(myID){
this.sID=myID;
}myObject.prototype.funA=function(){
document.onmousedown=this.funB;
}myObject.prototype.funB=function(e){
e = e||window.event;
alert("现在这是 onmousedown, 不是 myObject, e.type: "+e.type);
}function aa(){
var sw=new myObject("我的第五个测试!");
sw.funA();
}</script>
</head>
<body onload=aa()>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>shawl.qiu template</title>
<style type="text/css">
/* <![CDATA[ *//* ]]> */
</style>
<script type="text/javascript">
/*<![CDATA[*/
if (navigator.appName=="Microsoft Internet Explorer")
{
//最大化窗口
self.moveTo(-5,-5)
self.resizeTo(screen.availWidth +8,screen.availHeight+8)
//这个脚本定义的宽度其实比原窗口还要大那么一点.
}
/*]]*/
</script>
<script language="javascript">
function myObject(myID){
this.sID=myID;
}myObject.prototype.funA=function(){
var This = this;
document.onmousedown=function(){This.funB()};
}myObject.prototype.funB=function(e){
alert(this.sID)
}function aa(){
var sw=new myObject("我的第五个测试!");
sw.funA();
}</script>
</head>
<body onload=aa()>
</body>
</html>
document.onmousedown=this.funB这个语句中的this指得是document,因为语句本身就是一个函数
btbtd大哥在2楼里说的
document.onmousedown=function(){This.funB()};
我还有点疑问,为什么不可以改为这样的?
document.onmousedown=This.funB;
这两点有什么不同,问题可能比较低级,但我想了解原理,在这再次谢谢各位。
document.onmousedown=This.funB; 在这里This所表示的就不是对象了,而是一个函数(注可理解为函数的名),而This是引用this的函数对象,他是一个对象(代表的是函数)写成function(){This.funB()}是对象生效