Developing JavaScript Unit Test framework using MooTools

Source: Internet
Author: User
Tags extend mootools

MooTools is a good JavaScript framework, it is simple, modular, easy to use, developers can quickly start to write scalable, compatible with good JavaScript code. I used this for two days, feeling and prototype usage is exactly the same, but the function seems to strengthen, have a lot of effect, drag and drop. And it's object-oriented, inheritance more intuitive than prototype, so I began to learn this framework.

First look at the basic usage of mootools, and more detailed explanations can be found on the official website.

1.? If we're going to write a animal class, we can write this:

 var New Class ({
     function(name)
     {This
         . Name = name;
     }
 });

It's a lot like prototype's class.create, but I think it's more handy to use this. The variable defined by this is a member of a class that can be used arbitrarily in a class function.

If we're going to add new methods to the animal class, it's easy to just call the Extend method:

 Animal.extend ({
     function()
     {return this
         ": no Sound";
     }
 });

2. Element operation. MooTools uses the element class to encapsulate HTML elements, adding a number of common ways to look at the following code:

 var New Element (' div ', {
     ' styles ': {'
         width ''200px ',
         ' height ' ) ' 300px ',
         ' border '1px solid red '
     ,
     ' events ': {
         ' click ' function ()
         {
             alert (' test ');}}
 ). Inject (document.body);

is not very clear, the elements of the type, style, event, location is very clear expression, people at a glance and the amount of code is very small.

Related Article

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.