0

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);
        }
    });
4

1 回答 1

0

如果我理解正确,你想要

var options, element;
…
return function() {
    if (typeof options.func == 'function')
        return options.func(element.innerHTML);
};
于 2012-11-30T12:36:53.583 回答