使用 MooTools 调用 javascript 新函数
我找到了 Nivoo Slider 的 MooTools 版本(理论上)可以与我们的 MooTools 下拉菜单配合使用。但是,菜单使用的是 MooTools 1.2.x,Nivoo 使用的是 1.3.2 或 1.4.0。每次我尝试同时使用菜单和滑块时,菜单都会停止工作。
MooTools框架的版本不向后兼容吗?
另外,这些插件是否兼容,或者其中一个插件是否覆盖另一个插件?
我对 JS 的了解不够,无法纠正我的错误或重写函数调用。有这方面好的初学者教程吗?
window.addEvent('domready', function () {
var menu = new UvumiDropdown('dropdown-demo');
// initialize Nivoo-Slider
new NivooSlider($('slider'), {
directionNavHide: true,
effect: 'wipeDown',
interval: 1000
});
});
在尝试在不兼容的情况下进行转换时,以下是我不确定如何实施的说明。
Instruction
:: 1.2 代码行
$clear => use the native clearTimeout when using fn.delay, use clearInterval when using fn.periodical.
:: $clear(a.retrieve('closeDelay'))
myFn.create => Use the according functions like .pass, .bind, .delay, .periodical
:: this.createSubmenu(this.menu)
myFn.bind(this, [arg1, arg2, arg3]) => myFn.bind(this, arg1, arg2, arg3) OR myFn.pass([arg1, arg2, arg3], this)
:: this.domReady.bind(this)
$$ now only accepts a single selector, an array or arguments of elements
:: $$(b,b.getChildren ('li')
这些指令都具有兼容性。
myElement.get('tween', options); // WRONG
myElement.set('tween', options).get('tween'); // YES, INDEED.
:: this.menu.get('tag')!='ul'
:: this.menu.getElement('ul')
I have found a MooTools version of Nivoo Slider that (in theory) will work with our MooTools dropdown menu. However, the menu is using MooTools 1.2.x, and Nivoo is using 1.3.2 or 1.4.0. Every time I try and use both the menu and the slider, the menu stops working.
Are the versions of the MooTools framework not backward compatible?
Also, are these plugins compatible or is one overriding the other?
I don't know enough about JS to correct my errors or rewrite the function call. Is there a good beginner's tutorial for this?
window.addEvent('domready', function () {
var menu = new UvumiDropdown('dropdown-demo');
// initialize Nivoo-Slider
new NivooSlider($('slider'), {
directionNavHide: true,
effect: 'wipeDown',
interval: 1000
});
});
In trying to convert without compatibility, here are instructions that I was not sure how to implement.
Instruction
:: Line of 1.2 code
$clear => use the native clearTimeout when using fn.delay, use clearInterval when using fn.periodical.
:: $clear(a.retrieve('closeDelay'))
myFn.create => Use the according functions like .pass, .bind, .delay, .periodical
:: this.createSubmenu(this.menu)
myFn.bind(this, [arg1, arg2, arg3]) => myFn.bind(this, arg1, arg2, arg3) OR myFn.pass([arg1, arg2, arg3], this)
:: this.domReady.bind(this)
$ now only accepts a single selector, an array or arguments of elements
:: $$(b,b.getChildren('li')
These instructions are with compatibility. I'm trying both.
myElement.get('tween', options); // WRONG
myElement.set('tween', options).get('tween'); // YES, INDEED.
:: this.menu.get('tag')!='ul'
:: this.menu.getElement('ul')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我使用 mootools 1.4.x 测试了 UvumiDropdown 最新版本,只要我包含包含 Fx.Elements 的 Mootools 更多版本,它就可以正常工作
希望这会有所帮助
OK I tested the UvumiDropdown latest build with mootools 1.4.x and it worked fine as long as I included a Mootools more build that includes Fx.Elements
Hope this helps
MooTools 遵循 SemVer(语义版本控制),这意味着次版本号 (x.Y. z) 凹凸不保证向后兼容(并且通常不保证向后兼容)。
但是,新版本带有兼容层。如果您确实无法升级代码,只需勾选 MooTools Core builder 上的框即可。但您应该避免这样做,这对性能和潜在的前向兼容性不利。
至于教程,了解如何将代码从一个版本升级到另一个版本的最佳方法是阅读 1.3 的变更日志,了解与 1.2 的差异,以及 从 1.3 到 1.4 如果您想升级到最新版本。根据这些知识,重写所有使用过时 API 的调用。
乍一看,这似乎是一项艰巨的任务,但通常进展得很快(实际上,在这种情况下,最常见的是重写
Hash
引用和.each
调用) 。如果您正在学习 JS,这可能会很困难,但这绝对会是一次非常有益的 JS 体验,尤其是在 MooTools 中,因为您将了解是什么让代码变得“Mooish”:)MooTools follows SemVer (Semantic Versioning), meaning that a minor version number (x.Y.z) bump is not guaranteed to be backward-compatible (and is usually not).
However, new versions come with a compatibility layer. Just tick the box on the MooTools Core builder if you really can't upgrade your code. You should though avoid to do such a thing, it is bad for performance and potentially forward-compatibility.
As for a tutorial, the best way to learn how to upgrade code from one version to the other is to read the changelog of the 1.3 to learn about the differences with 1.2, and from the 1.3 to the 1.4 if you want to upgrade to the latest version. From this knowledge, rewrite all calls that make use of outdated APIs.
It looks like a daunting task at first, but it usually goes very quickly (actually, in this precise case, it is most often about rewriting
Hash
references and.each
calls). It might be hard if you're learning JS, but it will definitely be a very rewarding experience in JS, and especially in MooTools, as you'll learn about what makes a code ”Mooish” :)