08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 14 ■ JAVASCRIPT PROGRAMMING WITH <strong>ASP</strong>.<strong>NET</strong> <strong>AJAX</strong> 339<br />

types of boat, such as a speedboat, a yacht, a cruise liner, <strong>and</strong> so on. These all have something<br />

in common—that which makes them a boat—<strong>and</strong> something distinct, be it a<br />

motor, a sail, or a movie theater. Thus, the concept of inheritance means we can define a<br />

Boat class that contains the commonality <strong>and</strong> derive a SpeedBoat, Yacht, or CruiseShip<br />

class from this using inheritance.<br />

Listing 14-3 demonstrates this, extending the Boat class that you defined earlier, <strong>and</strong><br />

adding an outboard engine plus methods to activate it, giving us a speedboat.<br />

Listing 14-3. Using an Inherited Class<br />

Vehicles.SpeedBoat = function(boatSize, boatType, boatName, engineType)<br />

{<br />

Vehicles.SpeedBoat.initializeBase(this,[boatSize, boatType, boatName]);<br />

this._engineType = engineType;<br />

this._currentSpeed = 0;<br />

}<br />

Vehicles.SpeedBoat.prototype = {<br />

getEngineType: function(){<br />

return this._engineType;<br />

},<br />

setEngineType: function(){<br />

this._engineType = engineType;<br />

} ,<br />

checkEngine: function(){<br />

if (this._currentSpeed>0)<br />

return ("Engine is running at speed" + this._currentSpeed);<br />

else<br />

return "Engine is off";<br />

},<br />

startEngine: function(){<br />

if(this._currentSpeed == 0)<br />

this._currentSpeed = 1;<br />

else<br />

return "Engine is already running";<br />

},<br />

openThrottle: function(){<br />

if (this._currentSpeed0)<br />

this._currentSpeed--;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!