避免 Mootools 中的匿名函数?
这是我的问题:我正在寻找一种在 Mootools 中使用“非匿名”功能的方法。 找不到解决方法,也找不到有关它的文档。
示例: var myInput = new Element('输入', { 类型:'文本', 值:'你好世界', 事件:{模糊:函数(){ .... } }; });
或 $$('td[title]').addEvents('dblclick':function(){...});
和一个简单函数 function sayHello(){alert('hello')}
如果我希望 onBlur/ondblClick 事件调用现有函数(例如 sayHello),我该怎么办?我知道我可以在匿名函数中调用现有函数,但是有没有更好/合适的方法来执行该调用? 我被这个问题困扰了几天,也许它很简单,但我就是无法弄清楚。
谢谢。
编辑 : 我怎么会错过呢???谢谢你们的帮助,工作得很好!
Here's my problem: I'm looking for a way to work with 'not anonymous' function in Mootools.
Can't find a way to work it out, and I couldn't find doc about it.
Example:var myInput = new Element('input', {
type: 'text',
value: 'hello world',
events: {blur: function(){ .... }
};
});
OR$$('td[title]').addEvents('dblclick':function(){...});
AND a Simple functionfunction sayHello(){alert('hello')}
What should I do if I want onBlur/ondblClick event calls an existing function (eg. sayHello) ? I know I could call my existing function inside the anonymous one, but is there any better/suitable way to do that call ?
I'm stuck on that problem for a few days, maybe it's quite simple, but I simply can't figure it out.
Thank you.
EDIT :
How could I missed that ??? Thank you guys for the help, worked great !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因为函数是一个变量,所以您可以像使用变量一样使用它,在本例中作为哈希值,
我还应该指出,这两个函数将具有相同的名称:
它们都创建一个名为 ' sayHello'(有一些你现在不关心的细微差别)
because a function is a variable, you can use it as you would use a variable, in this case as a value of a hash
also i should point out that both of these functions will have the same name:
they both make a function called 'sayHello' (with subtle differences that you dont care about right now)
函数是 Javascript 中的一等公民,因此您可以像这样引用它们:
Functions are first class citizens in Javascript, so you can reference them like this:
只需直接传递对函数的引用,就像它是任何其他变量一样:
Simply pass in a reference to your function directly, as if it were any other variable: