Extend ES6 plugin to jQuery prototype

后端 未结 2 517
星月不相逢
星月不相逢 2021-02-02 02:00

I would like ask some help because i can\'t convert my classic jQuery (v2) plugin in ES6 with module and class.

In ECMAScript 5, we can attach jQuery plugin into jQuery

2条回答
  •  天涯浪人
    2021-02-02 02:22

    You install new methods on the jQuery prototype in ES6 just as you always did. Nothing has changed for them. You're not going to subclass jQuery, so it makes no sense to use class or extends.

    // myPlugin.es6:
    import $ from 'jquery';
    
    $.fn.myPlugin = function() {
        …
    };
    

    // app.es6:
    import $ from 'jquery';
    import 'myPlugin.es6';
    
    $('div').myPlugin();
    

提交回复
热议问题