【发布时间】:2016-05-10 06:41:05
【问题描述】:
我想寻求帮助,因为我无法在 ES6 中使用模块和类转换我的经典 jQuery (v2) 插件。
在 ECMAScript 5 中,我们可以像这样将 jQuery 插件附加到 jQuery 原型中:
app.js - 通过 HTML <script> 标签加载的 jQuery
$.fn.myPlugin = function() {};
$('div').myPlugin();
它有效:)。在 ES6 中,我会这样写:
myPlugin.es6:
import $ from 'jquery';
export default class myPlugin extends $ {
// Could i use constructor() method ???
}
app.es6:
import $ from 'jquery';
import myPlugin from 'myPlugin.es6';
$('div').myPlugin();
最后,它不起作用...
我已经搜索过,之前没有人问过这个问题。
我使用 Babel 将 ES6 转译成 ES5。
【问题讨论】:
-
extends $没有意义。你以为它和$.extend({…})的意思一样吗? -
如果您正在寻找新的 Javascript 功能,您可能不需要 jQuery。有很多不需要 jQuery 的独立 UI 库。此外,还有一个专门的网站youmightnotneedjquery.com 解释了如何从 jQuery 切换到原生功能。
标签: javascript jquery ecmascript-6 babeljs extend