是否可以使用 YUI 的 .on("click", ) 将参数传递给函数?例如,这是我正在查看的一些代码:
function foo1() {
var curObj = this;
this.foo2 = function() {
curObj.test = "foo2";
}
this.foo3 = function() {
curObj.test = "foo3";
}
// called by
this.blah = {};
var blah = this.blah;
blah['x'] = new YAHOO.widget.Button(x)
blah['x'].on("click", foo2)
blah['y'] = new YAHOO.widget.Button(y)
blah['y'].on("click", foo3)
}
我想通过执行以下操作来消除一些冗余:
function setTest(this, foo) {
this.test = foo;
}
function foo1() {
var curObj = this;
// called by
this.blah = {};
var blah = this.blah;
blah['x'] = new YAHOO.widget.Button(x);
blah['x'].on("click", thisTest("foo2"));
blah['y'] = new YAHOO.widget.Button(y);
blah['y'].on("click", thisTest("foo3"));
}
据我了解,YUI 会将“this”对象传递给从 .on(“click”, function) 调用的任何函数。
谢谢你的帮助。