0

I am working on a groupdocs viewer, and want to re-create plug-in like that,

groupdocs code below

(function ($) {
    var methods = {
        init: function (options) {
            debugger
            var defaults = {

            };
            options = $.extend(defaults, options);
        }
    }
    $.fn.viewer = function (method) {
        console.log(method)
        if (methods[method]) {
            return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
        } else if (typeof method === 'object' || !method) {
            return methods.init.apply(this, arguments);
        } else {
            $.error('Method' + method + ' does not exist on jQuery.viewer');
        }
    };
}(jQuery));

this code is working fine but when I create my custom code like below,

(function ($) {
    var methods = {
        init: function (options) {
            debugger
            var defaults = {

            };
            options = $.extend(defaults, options);
        }
    }
    $.fn.secondFunction = function (method) {
        if (methods[method]) {
           return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
       } else if (typeof method === 'object' || !method) {
           return methods.init.apply(this, arguments);
       } else {
           $.error('Method' + method + ' does not exist on jQuery.viewer');
       }
    };
}(jQuery));

secondFunction and event init: is not executing,

what might be the problem with my code

4

1 回答 1

0

Your code is working just fine. Open the inspector and run press the run button below, and you will see that it pauses on the debugger statement.

(function ($) {
    var methods = {
        init: function (options) {
            debugger
            var defaults = {

            };
            options = $.extend(defaults, options);
        }
    }
    $.fn.secondFunction = function (method) {
        if (methods[method]) {
           return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
       } else if (typeof method === 'object' || !method) {
           return methods.init.apply(this, arguments);
       } else {
           $.error('Method' + method + ' does not exist on jQuery.viewer');
       }
    };
}(jQuery));

$().secondFunction();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

于 2020-03-19T10:53:35.147 回答