懂javascript的过来看段代吗。我怎么看不明白啊。

Naola2001 2003-07-22 04:10:31
从国外站点down了一个js文件,头一个函数就看不明白,烦请大家解释一下,是干嘛的?

var CalendarHandler = {
idCounter : 0,
idPrefix : "webfx-tree-object-",
all : {},
behavior : null,
selected : null,
onSelect : null, /* should be part of tree, not handler */
getId : function() { return this.idPrefix + this.idCounter++; },
toggle : function (oItem) { this.all[oItem.id.replace('-plus','')].toggle(); },
select : function (oItem) { this.all[oItem.id.replace('-icon','')].select(); },
focus : function (oItem) { this.all[oItem.id.replace('-anchor','')].focus(); },
blur : function (oItem) { this.all[oItem.id.replace('-anchor','')].blur(); },
keydown : function (oItem, e) { return this.all[oItem.id].keydown(e.keyCode); },
cookies : new WebFXCookie(),
insertHTMLBeforeEnd : function (oElement, sHTML) {
if (oElement.insertAdjacentHTML != null) {
oElement.insertAdjacentHTML("BeforeEnd", sHTML)
return;
}
var df; // DocumentFragment
var r = oElement.ownerDocument.createRange();
r.selectNodeContents(oElement);
r.collapse(false);
df = r.createContextualFragment(sHTML);
oElement.appendChild(df);
}
};
...全文
39 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Naola2001 2003-07-23
  • 打赏
  • 举报
回复
咔咔卡,是Xtree 俺要把他搞成超级 Calendar

重复劳动,没意义呵
hahacc 2003-07-22
  • 打赏
  • 举报
回复
确实是定义的一个类的声明:
idCounter : 0,
idPrefix : "webfx-tree-object-",
all : {},
behavior : null,
selected : null,
onSelect : null, /* should be part of tree, not handler */
以上是定义常量。

getId : function() { return this.idPrefix + this.idCounter++; },
getId是属性,假设调用这个属性则该函数的返回值是"webfx-tree-object-"+idCounter++;
应该是函数个数的计算方式。
以下的应该可以类推。
ydr2002 2003-07-22
  • 打赏
  • 举报
回复
这是他自己定义了一个CalendarHandler对象或叫类,里面有属性和方法,
idCounter : 0, 这样的是属性;
getId : function() { return this.idPrefix + this.idCounter++; },这样的是方法;
使用的时候如:
var calendarhandler = new CalendarHandler();
calendarhandler.idCounter = 1 //给属性 idCounter
calendarhandler.getId(); //调用getId方法

这个类具体是什么作用要看环境,这个好像是eae.webfx.net上的xtree里的东西

87,988

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧