MooTools 1.2 Beginner's Guide
上QQ阅读APP看书,第一时间看更新

Time for action—determining the value of our options

The following steps help us to determine the value of our options:

  1. Right below where we use the .bark() method on myDog, type in the following code:
    document.write( 'My dog\'s name is ' + myDog.options.name + '.<br />');
    document.write( 'My dog is a ' + myDog.options.type + '.<br />');
    document.write( 'My dog is ' + myDog.options.age + ' years old.<br />');
    
  2. Open up your HTML document on the web browser, and after you exit out of the dialog box that .bark() calls, you should see something like this:
    Time for action—determining the value of our options

Extending classes

Oftentimes, you'll want to extend a class with another class. For example, we might want to extend our Dog class with a class for show dogs that may use the same options, but may do other special things.

We can extend classes with the Extends property. Extends is a property specifically for classes, that not only inherits properties and methods from a parent class, it makes all parent methods available inside a method.