Your SlideShare is downloading. ×
0
Class
Class
Class
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Class

286

Published on

Prototype Javascript

Prototype Javascript

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
286
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  1. Module Class
  2. Class <ul><li>create() -> Function </li></ul><ul><li>Returns an function that acts like a Ruby class </li></ul><ul><li>Class.create() returns a function that, when called, will fire its own initialize method. This allows for more Ruby-like OOP. It also lets you more easily subclass by overriding a parent's constructor. </li></ul>
  3. Class <ul><li>Example </li></ul><ul><li>var  Animal = Class.create(); </li></ul><ul><li>Animal.prototype = {  initialize:  function (name, sound) </li></ul><ul><li>  {    this.name  = name;    this.sound = sound;  },  </li></ul><ul><li>   speak:  function () {    alert(name +  &quot; says: &quot;  + sound +  &quot;!&quot; );  } </li></ul><ul><li> }; </li></ul><ul><li>var  snake =  new  Animal( &quot;Ringneck&quot; ,  &quot;hissssssssss&quot; ); </li></ul><ul><li>snake.speak();// -> alerts &quot;Ringneck says: hissssssssss!“ </li></ul><ul><li>  var  Dog = Class.create(); Dog.prototype = Object.extend( new  Animal(), {  </li></ul><ul><li>  initialize:  function (name) {    this.name  = name; this.sound =  &quot;woof&quot; ;  }  }); </li></ul><ul><li>var  fido =  new  Dog( &quot;Fido&quot; ); </li></ul><ul><li>fido.speak(); </li></ul><ul><li>// -> alerts &quot;Fido says: woof!&quot; </li></ul>

×