如何获得我的javascript类? [英] how to get my javascript class?

查看:69
本文介绍了如何获得我的javascript类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



对于javascript来说还是一个新手我正在抓住以下问题,希望有人可以帮助我...


我有一个javascriptclass看起来如下(只显示相关部分)

Hi,
being quite new to javascript I''m scratching my head to the following issue, hope someone can help me...

I''m having a javascript "class" that looks like follows (just showing relevant parts)

展开 | 选择 | Wrap | 行号

推荐答案

setInterval()(以及其他一些方法*)改变了被调用函数中 this 的范围。在这种情况下第一次这个(在 trace(this.x)中)引用 control ,第二次到 window


* window 的大多数方法和每个事件处理程序
setInterval() (along with some other methods*) alter the scope of this in the called function. in this case the first time this (in trace(this.x)) refers to control, the second time to window.

* most methods of window and every event handler


是的,那是什么我怀疑了。但在第二种情况下(在隐藏方法中),如何访问控件对象?

谢谢。
yes, that''s what I suspected. But in the second case (in the hide method), how do I access the control object?
Thanks.


@olaalo


你可以吗?因为对象 control 在这里不存在(它是变量名!)。不过你可以通过 call()函数手动设置 this
@olaalo
you can?t because the object control does not exist here (it?s a variable name!). nevertheless you can manually set this by the call() function.
展开 | 选择 | 换行 | 行号


这篇关于如何获得我的javascript类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆