官术网_书友最值得收藏!

Chapter 2. Writing JavaScript with MooTools

Using MooTools means you'll be coding in a web application framework that excels in object-oriented programming and JavaScript best practices. Modern development principles, such as unobtrusive JavaScript programming and object-based logic is the bread and butter of MooTools.

For example, modern development practices dictate that we separate our site's functional and behavioral layers (server-side and client-side scripts) from our site's content structural layer (HTML markup). This concept is known as unobtrusive JavaScript, and we'll delve into this best practice here in this chapter. You'll see one of the more important ways of how MooTools makes us write better JavaScript.

But we're going to be covering more than just unobtrusive JavaScript. We're going to work with classes, which is the design pattern of the entire MooTools framework.

MooTools is structured into classes. In programming, a class is simply a template of an object. A class can contain many methods or properties such as normal variables or even references to other classes and objects.

To understand how to write great MooTools code that adheres to best practices, you have to understand its fundamental structure and the concept of classes, which I must admit, can be confusing and hard to grok.

If you know another programming language, especially an object-oriented one, or a pseudo-object-oriented one like PHP (this is where I learned the concept of a class), then the stuff we'll discuss here will look very familiar to you. You can then compare and contrast the difference in syntax of classes in your particular language. As an example, for you PHP folks out there, in PHP 5, we have the __construct() function, which you'll soon see, is exactly like the initialize method of a MooTools class.

In this chapter we shall:

  • Learn how MooTools helps us write unobtrusive JavaScript
  • Work with classes by creating our own class
  • See how MooTools works by exploring a couple of classes
  • Learn about the concept of chainability by working through a simple animation example

So let's get on with it!

主站蜘蛛池模板: 江阴市| 白银市| 岳阳市| 当雄县| 天峨县| 沙洋县| 历史| 临颍县| 襄汾县| 凌海市| 彰武县| 凉城县| 凤凰县| 普宁市| 探索| 淅川县| 福贡县| 扬州市| 沈丘县| 东乡县| 棋牌| 原阳县| 公主岭市| 陇川县| 鹤峰县| 温泉县| 博爱县| 长乐市| 崇阳县| 永嘉县| 原阳县| 泌阳县| 乡城县| 云龙县| 苏尼特左旗| 红原县| 建始县| 池州市| 岢岚县| 汝阳县| 烟台市|