http://jsbin.com/ukizof/1/ 如何调用作为数组一部分的函数并为其设置参数,如下例所示,我希望脚本返回一个函数以调用函数参数,如下面的示例所示。
var bQuery = {
one: function(elem, options) {
options = this.extend({
method: 'html',
event: 'test2',
func:null
}, options || {});
var element = elem;
if (options.method == 'html') {
element.innerHTML = options.event;
} else if (options.method == 'append') {
element.innerHTML = element.innerHTML + options.event;
} else if (options.method == 'prepend') {
element.innerHTML = options.event + element.innerHTML;
}
return // return method to apply string to func: parameter function as below is "e"
},
extend: function(a, b) {
for (var prop in b) {
a[prop] = b[prop];
}
return a;
}
};
$ = bQuery;
$.one(document.getElementById("log"), {
method: 'append',
event: 'rjfjfjjffj',
func: function(e){
alert(e);
}
});
答案 0 :(得分:0)
如果我理解你,你想要
var options, element;
…
return function() {
if (typeof options.func == 'function')
return options.func(element.innerHTML);
};