Update from 1.2 to 1.3

lorenzos edited this page on 8 Jul 2011 · 2 revisions

MooTools Core 1.3 is backwards compatible with all the documented features of MooTools Core 1.2 through an inbuilt compatibility layer. This guide helps you avoid minor problems while updating. If you want to drop the compatibility layer see the upgrade guide: Upgrade from 1.2 to 1.3

Function.prototype.bind

MooTools has provided an implementation of this method for years, however the new ECMAScript 5 specification describes a different behavior. If you use the compatibility layer, the 1.2 version of "bind" will be used. If you drop the compatibility layer, the implementation equals to that of the ECMAScript 5 specification and it uses the native implementation of a browser, if available (Chrome 6, Firefox 4, …).

The difference in both versions is that the specification takes any amount of arguments and the MooTools version only takes an array as second argument.

Example:

myFn.bind(this, arg1, arg2, arg3); // ES5 Spec
myFn.bind(this, arguments); // MooTools Core 1.2

To avoid possible problems once you drop the compatibility layer you can use the following script to automatically convert all occurrences of bind with arguments to the "pass"-method that we provide in MooTools.

Replace bind

To ensure compatibility with the plugins you release, you should not use bind with arguments (ie, just use .bind(thisArg)) and resort to using Function.prototype.pass. This method works like our old implementation of "bind" with reversed argument order.

Example

myFn.bind(this, arguments); // DON'T do this anymore
myFn.pass(arguments, this); // YES

Element.get / Element.set compatibility

In the past, these two methods were able to take any amount of arguments. This was undocumented but used by some people. To bring back the old 1.2 behavior you can use the following script: Element.get/Element.set.

Please use the above script at your own risk. In order to update from 1.2 to 1.3, you should replace any occurrences of the Element.get method with options like this:

myElement.get('tween', options); // WRONG
myElement.set('tween', options).get('tween'); // YES, INDEED.

Request

The get/post/put/delete methods used to accept the URL as argument rather than the data. Our documentation however only described to send data via those methods, so this behavior was fixed in 1.3. Instead of passing the URL via the .get/.post/.put/.delete methods, pass the URL as option when you create the Request instance.

JSON (since 1.3.1)

JSON.decode can throw errors when the secure argument is set to true. This is the same behavior as the native JSON.parse. Also this native function will be used if it's available (in all modern browsers). Previously just null was returned.

JSON.decode('no valid json string', true); // `null` in < 1.3.1

try { // 1.3.1
JSON.decode('no valid json string', true);
} catch(e){
console.log('failed to decode JSON');
}
// or a little shorter and easier to update
JSON.decode.attempt(['no valid json string', true]);
===========

Upgrade from 1.2 to 1.3 or 1.4

arian edited this page on 13 Jun 2012 · 1 revision

This is a list of the API changes made from 1.2 to 1.3. It allows you to drop the compatibility layer mostly by doing search and replace. If you just want to update to MooTools Core 1.3 with your existing code, see Update from 1.2 to 1.3.

Core

  • $chk(value) => (value != null)
  • $A(item) => Array.from(item) // Note: Array.from does not always return a new array but just ensures that the return value is an array.
  • $splat => Array.from
  • $clear => use the native clearTimeout when using fn.delay, use clearInterval when using fn.periodical.
  • $defined => (value != null)
  • $each => use Array.each for arrays, Object.each for objects
  • $empty => No replacement, use function(){}
  • $extend(source, extended) => Object.append(source, extended)
  • $merge(a, b) => Object.merge({}, a, b)
  • $mixin(a, b) => Object.merge(a, b)
  • $lambda => Function.from
  • $random => Number.random
  • $time => Date.now
  • $type => typeOf // Note: returns a string 'null' on empty objects as opposed to "false" in 1.2
  • $unlink => Array.clone or Object.clone
  • $arguments => No replacement
  • Native => Type (see Core.js)
  • Array.type / String.type / Number.type / … => Type.isArray / Type.isString / Type.isNumber / …
  • Hash and $H were deprecated and moved from Core to More. Use plain objects instead of Hash. You can find methods to manipulate objects on Object. You can find all 1.2 functionality of Hash in MooTools More 1.3.

Browser

Engine detection was changed in favor of user-agent detection. Browser.Engine was deprecated and according properties on the Browser object were added:

  • Browser.Engine.trident => Browser.ie
  • Browser.Engine.gecko => Browser.firefox
  • Browser.Engine.webkit => Browser.safari or Browser.chrome
  • Browser.Engine.presto => Browser.opera
  • Browser.Platform.ipod => Browser.Platform.ios
  • $exec => Browser.exec

Array

  • $pick => Array.pick or [a, b, c].pick()
  • Array.extend => Array.append

Function

  • $try => Function.attempt
  • myFn.run(args, bind) => myFn.apply(bind, Array.from(args));
  • myFn.create => Use the according functions like .pass, .bind, .delay, .periodical
  • myFn.bindWithEvent => deprecated
  • myFn.bind(this, [arg1, arg2, arg3]) => myFn.bind(this, arg1, arg2, arg3) OR myFn.pass([arg1, arg2, arg3], this)

Element

  • element.injectInside, .injectBefore, .injectAfter, .injectBottom, .injectTop => element.inject(context, where); // where = inside, bottom, …
  • element.grabTop, … => element.grab(context, where) // see above
  • element.hasChild(item) => item !== element && element.contains(item)
  • $$ now only accepts a single selector, an array or arguments of elements
  • Selectors.Pseudo => Slick.definePseudo(name, fn)

Changes for 1.4

Event

  • Event => DOMEvent
  • Event.Keys.foo = 49 => DOMEvent.defineKeys(49, 'foo');

mootools upgrate from 1.2 to 1.3 or 1.4的更多相关文章

  1. 初次接触mootools

    以下是今天所学代码,网上有这篇博客可供参考,另外还是推荐官方文档 ,以下是今天所敲代码: //用mootools创建类的方式: //方式1:用标准方式传入一个对象字面量 /* var Person = ...

  2. Mootools插件-闪烁的标题

    转自:http://www.cnblogs.com/see7di/archive/2012/10/09/2716024.html 回想起来,我已经好久没有写点啥了,尤其是关于Mootools方面的东西 ...

  3. js在mootools框架下的new Class

    首先,在HTML文件中引入mootools.js. mootools-more.js.mootools-core.js,然后就能使用mootools封装的一些特性. 几乎类似于面向对象. mootoo ...

  4. mootools里选择器$,$$,$E,$ES等的区别

    区别就是 $和$$都是1个参数, $适用于ID,或者ID代表的对象 $$适用于CSS选择器 $E和$ES,有2个参数,第二个参数是可选参数代表(filter,即某个ID范围里的元素) $E('inpu ...

  5. mootools和jquery冲突的解决

    mootools-jquery 今天在做EcStore前台的做效果时,由于Jquery的插件比较多,于是就使用了Jquery的插件,但是发现会引起Mootools的冲突. 于是猛找资料,终于找到了,现 ...

  6. 【MooTools】

    MooTools a compact javascript frameworkhttp://mootools.net/docs/core 30天学会 MooTools 教学(1): 认识MooTool ...

  7. MOOTOOLS简单操作应用知识

    在项目中我们经常需要用到全选/反选.等操作按钮. 基于mootools框架与jquery框架不一致.导致缓慢. $('chkall').addEvent('click',function(){ if( ...

  8. MOOTOOLS和JQUERY如何同时存在,解决冲突

    mootools-jquery 今天在做EcStore前台的做效果时,由于Jquery的插件比较多,于是就使用了Jquery的插件,但是发现会引起Mootools的冲突. 于是猛找资料,终于找到了,现 ...

  9. MooTools 异步请求验证

    http://www.chinamootools.com/ 问题 MooTools 异步请求例子 <{foreach from=array('0','1','2','3','4') item=c ...

随机推荐

  1. 搬家后Magento前台只有产品的缩略图不显示

    第一种可能:缓存不足 http://blog.csdn.net/ddjohn/article/details/6648199 最近发现一个怪异的现象,Magento前台只有产品的缩略图不显示.我检查了 ...

  2. Java TCP Swing聊天程序

      http://www.oschina.net/code/snippet_935786_52805   业余写着玩的,好多功能没实现,有兴趣的可以拿去玩玩.图片大了还上不了,额.下载地址 http: ...

  3. 十五个最常用Linux命令行 - imsoft.cnblogs

    众多Linux管理员在使用Linux的时候会经常使用到很多Linux命令行,其中有绝大部分不是经常使用到的.在本文中主要为大家总结了经常使用的十五个最常用Linux命令行,希望对刚刚接触Linux命令 ...

  4. db2 字符串转换 数字

    今天使用聚合函数的时候 发现 varchar类型的是不可用的,所以呢就开始想办法解决 用到了转换函数cast(s.score as bigint) 然后有一个问题就是如果数据为空的话就会发生转换错误. ...

  5. HOG 梯度方向直方图简介(转载)

    一.基本HOG算法 HOG特征最早出现在SIFT算法中,由于其极强的图像特征描述能力,逐渐被人们熟知和广泛运用,其在目标检测方面表现尤为突出. HOG特征提取过程 步骤一:遍历图像每个像素点,以其为中 ...

  6. C语言的位运算

    位运算加速技巧1. 如果乘上一个2的倍数数值,可以改用左移运算(Left Shift) 加速 300% x = x * 2;x = x * 64;//改为:x = x << 1; // 2 ...

  7. Lumia刷机Win10 Mobile 10.0.10166惊魂记

    1 手贱,不愿等正式版正式发布,结果手动更新了,为此还熬了两个晚上. 2 第一次撞上去,没有无线了,倒.一开始还以为是预览版BUG,后来查了下重置就可以了,可以没有3G,没有WIFI也没办法备份,干, ...

  8. hdu1114 Piggy-Bank ——完全背包

    link:http://acm.hdu.edu.cn/showproblem.php?pid=1114 只不过求得是最小值.没什么可说的,连我都会做……o(╯□╰)o /* ID: zypz4571 ...

  9. c 函数及指针学习 7

    1.结构的存储分配 1 2 printf("%d \n",sizeof(char)); printf("%d \n",sizeof(int)); int 类型为 ...

  10. input子系统详解

    一.初识linux输入子系统 linux输入子系统(linux input subsystem)从上到下由三层实现,分别为:输入子系统事件处理层(EventHandler).输入子系统核心层(Inpu ...