MooTools Upgrate from 1.2 to 1.3 or 1.4

Source: Internet
Author: User

Update from 1.2 to 1.3lorenzos edited this page on 8 Jul 2011 · 2 RevisionsPages
    • Home
    • Home
    • Changelog
    • Conversion from 1.11 to 1.2
    • Create a bug Demo
    • How the MooTools Dev Team contributes
    • How to Contribute
    • Intro
    • License
    • MooTools Contributors
    • MooTools Tutorials
    • Olmo ' s workflow
    • Repository Structure
    • Sites using MooTools
    • Support
    • Show 4 More pages ...
Clone this wiki locallyClone in Desktop

MooTools Core 1.3 is backwards compatible and all the documented features of MooTools Core 1.2 through an inbuilt Compati Bility 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 have provided an implementation of this method for years, however the new ECMAScript 5 specification describes a D Ifferent behavior. If You use the compatibility layer, the 1.2 version of "Bind" would be used. If you drop the compatibility layer, the implementation equals to that of the ECMAScript 5 specification and it uses the N ative implementation of a browser, if available (Chrome 6, Firefox 4, ...).

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

Example:

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

To avoid possible problems once your 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 anymoremyFn.pass(arguments, this); // YES
Element.get/element.set compatibility

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

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); // WRONGmyElement.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 is described to send data via those methods, so this behavior is 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 ins Tance.

JSON (since 1.3.1)

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

JSON.decode(‘no valid json string‘, true); // `null` in < 1.3.1try { // 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 updateJSON.decode.attempt([‘no valid json string‘, true]);


===========


Upgrade from 1.2 to 1.3 or 1.4arian edited this page on June 2012 · 1 revisionPages
    • Home
    • Home
    • Changelog
    • Conversion from 1.11 to 1.2
    • Create a bug Demo
    • How the MooTools Dev Team contributes
    • How to Contribute
    • Intro
    • License
    • MooTools Contributors
    • MooTools Tutorials
    • Olmo ' s workflow
    • Repository Structure
    • Sites using MooTools
    • Support
    • Show 4 More pages ...
Clone this wiki locallyClone in Desktop

This is a list of the APIs changes made from 1.2 to 1.3. It allows 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 VA Lue is an array.
  • $splat = Array.from
  • $clear = Use the native cleartimeout if 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 hashes in MooTools more 1.3.
Browser

Engine detection is changed in favor of user-agent detection. Browser.engine is 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-accepts a single selector, an array or arguments of elements
    • Selectors.pseudo = Slick.definepseudo (name, FN)
Changes for 1.4Event
    • Event = DomEvent
    • Event.Keys.foo = Domevent.definekeys (+, ' foo ');

MooTools Upgrate from 1.2 to 1.3 or 1.4

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.