Tag: 样板

使用jQuery插件设计模式调用方法

我一直在使用jQuery Boilerplate开发插件,而我无法弄清楚的一件事是如何从插件外部调用方法。 作为参考,这里是我正在谈论的样板代码: http : //jqueryboilerplate.com/ 在我的小提琴, http://jsfiddle.net/D9JSQ/2/ 这是代码: ;(function ( $, window, document, undefined ) { var pluginName = ‘test’; var defaults; function Plugin(element, options) { this.element = element; this.options = $.extend( {}, defaults, options) ; this._name = pluginName; this.init(); } Plugin.prototype = { init: function() { this.hello(); }, hello : function() { document.write(‘hello’); […]

使用’window’,’document’和’undefined’作为包装jQuery插件的匿名函数中的参数

老实说,我不知道如何缩短标题。 我通过研究SlidesJS插件的来源学习了如何编写jQuery插件。 当我遇到一些新的东西时,我只是问了我的好朋友谷歌并且大多数时候都得到了满意的答案。 老实说,我从来没有做过多少努力。 我所知道的是$ (可能)是一个简写的jQuery对象构造函数,并且$()和jQuery()是相同的东西,只要包含jQuery。 不过,最近,我试图理解jQuery背后的科学以及如何编写一个好的 jQuery插件。 我遇到了一篇非常好的文章 ,其中作者列出了几个用于创建jQuery插件的模板 。 由于其余部分太复杂,我无法理解,我喜欢第一个: 轻量级开始 。 现在,这是所述模板的代码。 /*! * jQuery lightweight plugin boilerplate * Original author: @ajpiano * Further changes, comments: @addyosmani * Licensed under the MIT license */ // the semi-colon before the function invocation is a safety // net against concatenated scripts and/or other plugins […]