Let's see how we can extend our Dog
class using the Extends
property:
Let's clean up the
Dogs
class first by removing the things we don't need any more to tidy up our code. We'll delete the.sit()
class method, themyDog.bark()
call, and thedocument.write's
that we used to show the option property values ofmyDog
. Here's our revised code:<html> <head> <script type="text/javascript" src="mootools-1.2.1-core-nc.js"> </script> <script type="text/javascript"> window.addEvent('domready', function() { var Dog = new Class( { Implements : [ Options ], options : { name : 'Barkee', type : 'Poodle', age : 4 }, initialize : function( options ) { this.setOptions( options ); }, bark : function() { alert( this.options.name + ' is barking.' ); } }); }); </script> </head> <body> </body> </html>
Create the
ShowDog
class right below theDog
class. Use the following code:var ShowDog ...