How to retrofit jquery plug-ins with AMD specification examples

Source: Internet
Author: User

UMD dance-https://github.com/umdjs/umd!function (root, Factory) {if (typeof define = = = ' function ' && define.  AMD) {define ([' jquery '], factory);  } else {factory (root.jquery);  }} (this, function ($) {' Use strict ';  Default options var defaults = {};    Constructor, initialise everything you need here var Plugin = function (element, options) {this.element = element;  this.options = options;  }; Plugin methods and Shared Properties Plugin.prototype = {//Reset Constructor-http://goo.gl/ecwdiy Constructo R:plugin, Somemethod:function () {}}//Create the jQuery Plugin $.fn.plugin = function (options) {//do a    Deep copy of the OPTIONS-HTTP://GOO.GL/GOSSRG options = $.extend (true, {}, defaults, options);      Return This.each (function () {var $this = $ (this); Create a new instance for each element in the matched JQuery set//Also Save the instance so it can be accessed L    Ater to use methods/properties etc  e.g.      var instance = $ ('. Element '). Data (' plugin ');      Instance.somemethod ();    $this. Data (' plugin ', new plugin ($this, options));  });  }; Expose defaults and Constructor (allowing overriding of prototype methods for example) $.fn.plugin.defaults = Defaults  ; $.fn.plugin.plugin = plugin;});     /use case, Jquery.plugin is the identifier of the above plugin require ([' jquery ', ' jquery.plugin '], function ($) {$ ('. Test li '). Plugin ({test: ' option1 ', Test2: ' Option2 '});



How to retrofit jquery plug-ins with AMD specification examples

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.