jQuery Plugin: Adding Callback functionality

后端 未结 6 1798
孤街浪徒
孤街浪徒 2020-11-28 00:40

I\'m trying to give my plugin callback functionality, and I\'d like for it to operate in a somewhat traditional way:

myPlugin({options}, function() {
    /*          


        
6条回答
  •  盖世英雄少女心
    2020-11-28 01:18

    An example bit late, but it can be useful. Using arguments can create the same functionality.

    $.fn.myPlugin = function() {
        var el = $(this[0]);
        var args = arguments[0] || {};
        var callBack = arguments[1];
        .....
        if (typeof callback == 'function') {
            callback.call(this);
        }
    }
    

提交回复
热议问题