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')?? 這是怎樣調用init方法的??這樣寫不是將init作為參數傳遞進去了?
??????????????????? if ($.type(options) == "string") {
??????????????????????? return instance[options]();
??????????????????? }
??????????????? })
??????????? }
2017-02-07
?if ($.type(options) == "string") {
? ? ? ? return instance[options]();
? ? }
這里他在演示如果需要調用init方法需要怎么做。
他這里有判斷如果傳進去是個字符串的話,就調用實例上面的對應的方法。
instance[options]();
這里instance是instance = new PageSwitch($me, options);?
實例可以調用構造函數prototype上的方法。