// Define the Pet class. This depends on the existence of the // jQuery library for its definition. // // NOTE: jQuery isn't loaded as a module; it's simply added to the // global name-space. define( [ "jquery-1.6.4.js" ], function( _jquery_ ){ // I am an internal counter for ID. var instanceID = 0; // I am the class constructor. function Pet( type, name ){ // Get the instance ID. this._id = ++instanceID; // Store the type. this._type = type; // Store the name value. this._name = name; } // Define some constants. Pet.CAT = 1; Pet.DOG = 2; Pet.BIRD = 3; Pet.FISH = 4; Pet.RODENT = 5; // Define the prototype. Pet.prototype = { // I return the id. getID: function(){ return( this._id ); }, // I return the name. getName: function(){ return( this._name ); }, // I return the current type. getType: function(){ return( this._type ); }, // I set the new name. setName: function( name ){ // Store the new value. this._name = name; // Return this object reference for method chaining. return( this ); } }; // -------------------------------------------------- // // -------------------------------------------------- // // Return the constructor. return( Pet ); } );