내가 뭘 잘못 했니? jquery 문서에 제안 된대로 메서드를 분리하기 전에 작동했습니다. 콜링 : $(this).Slick('show');
이 간단한 jquery 플러그인 예제에는 어떤 문제가 있습니까?
(function ($) {
var methods = {
// object literals for methods
init: function (options) {
// initialize settings
var settings = $.extend({
'location': 'center',
'speed': 'normal'
}, options);
},
show: function() {
return this.each(function() {
// plugin code here
alert('success!');
});
},
hide: function() {
// hide
}
};
$.fn.Slick = function (method) {
// method calling logic -- jquery recommended/standard
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.Slick');
}
};
})(jQuery);
을 통해 일반적인 jQuery를 방식으로 작동합니다 jQuery 플러그인 설정을 시작하는 데 필요한 모든 것을 제공 "나는 방법을 분리하기 전에 그것은 일했다" 그것이 일했던 국가에. 그리고 다시 한 번 한 줄씩 작은 단계로 반복하십시오. 각각의 작은 반복 후에 모든 것이 예상대로 작동하는지 확인하십시오. 당신이 깨졌을 때 - 정확히 작은 부분의 변화가 무엇인지 정확히 알 수 있습니다 (** 디버깅 **이라고 함) – zerkms