<SCRIPT LANGUAGE="JavaScript">
<!--
var A = function(){
this.X()
}
A.prototype = { X:function(){
this.Y();
var th = this;
var Timer = setInterval(function(){th.Z();},1000);
},
Y:function(){},
Z:function(){alert("z run");} }
var a = new A();
//-->
</SCRIPT>
<!--
var A = function(){
this.X()
}
A.prototype = { X:function(){
this.Y();
var th = this;
var Timer = setInterval(function(){th.Z();},1000);
},
Y:function(){},
Z:function(){alert("z run");} }
var a = new A();
//-->
</SCRIPT>
this.X()
...
...
}
//也可以把你要实现的A的功能都写在里边,当作一个对象的方法来调用为什么 this.Z() 的 this 是 window 希望是A
//不用this可否??A.prototype =
//这种用法我在一些老外的网站上经常见,可能是习惯问题,自己喜欢就好了
都写在里面 怎么写 我也想都写在里面阿function A{ A.prototype.X = function(){}
A.prototype.Y = function(){}}
还是怎么写
因为 this.Z() 我就是想用 A.Z() 阿 他变成 window.Z() 我就用不到哇
不用 this 没有公用变量 怎么引用的这个方法阿
不过我就纳闷 问什么变了呢 this 为什么变了呢 只与 我这个计时器写法有关么?我要在 function A(){
this.a = '2121';
var b = 'sad';
}
我这个 b 怎么在方法里 搞到它 多谢 障碍啊 希望点播
A.prototype.Y = function(){}}
============================
function A()
{
this.X=function(){alert('class A:fun_X()');};
this.Y=function(){alert('class A:fun_Y()');};
}
var a=new A();
a.X();
a.Y();这么写有两个相关问题:1.对象的公用方法 2.闭包
你去查查资料看吧
this.a = '2121';
var b = 'sad';
}多谢 多谢 先学习 日后请教
this.a = '2121';
var b = 'sad';
this.getBvalue=function(){return b;};
}var a=new A();
alert(a.getBvalue());你在A里面var声明了b,它只能做为A的私有变量了,所以你必须写一个方法getBvalue()来得到它,用 a.getBvalue()可以 a.b是不行的
你们 有挂 qq msn 的 么
375138677 [email protected] 同行 赐教 交流