2-1 12:10秒处有疑问

来源:2-1 如何实现jQuery插件框架

慕粉1467970169

2016-12-11 20:07

$.fn.PageSwitch = function(options) {
                return this.each(function() {
                    var $me = $(this);
                    var instance = $me.data("PageSwitch")
                    if (!instance) {
                        instance = new PageSwitch($me, options);
                        $me.data("PageSwitch", instance)
                    }

                    $('div').PageSwitch('init')   这是怎样调用init方法的??这样写不是将init作为参数传递进去了?

                    if ($.type(options) == "string") {
                        return instance[options]();
                    }
                })
            }

写回答 关注

1回答

  • 姜芽儿
    2017-02-07 18:32:09

     if ($.type(options) == "string") {
            return instance[options]();
        }

    这里他在演示如果需要调用init方法需要怎么做。

    他这里有判断如果传进去是个字符串的话,就调用实例上面的对应的方法。

    instance[options]();

    这里instance是instance = new PageSwitch($me, options); 

    实例可以调用构造函数prototype上的方法。

全屏切换效果

如何在PC和移动端实现全屏切换效果,本课程会给你答案

85457 学习 · 166 问题

查看课程

相似问题