2-1 12:10秒處有疑問
$.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')?? 這是怎樣調(diào)用init方法的??這樣寫不是將init作為參數(shù)傳遞進(jìn)去了?
??????????????????? if ($.type(options) == "string") {
??????????????????????? return instance[options]();
??????????????????? }
??????????????? })
??????????? }
2017-02-07
?if ($.type(options) == "string") {
? ? ? ? return instance[options]();
? ? }
這里他在演示如果需要調(diào)用init方法需要怎么做。
他這里有判斷如果傳進(jìn)去是個字符串的話,就調(diào)用實例上面的對應(yīng)的方法。
instance[options]();
這里instance是instance = new PageSwitch($me, options);?
實例可以調(diào)用構(gòu)造函數(shù)prototype上的方法。