Your SlideShare is downloading. ×
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

276

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
276
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
    • create() -> Function
    • Returns an function that acts like a Ruby class
    • 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.
  • 3. Class
    • Example
    • var  Animal = Class.create();
    • Animal.prototype = {  initialize:  function (name, sound)
    •   {    this.name  = name;    this.sound = sound;  }, 
    •    speak:  function () {    alert(name +  " says: "  + sound +  "!" );  }
    • };
    • var  snake =  new  Animal( "Ringneck" ,  "hissssssssss" );
    • snake.speak();// -> alerts "Ringneck says: hissssssssss!“
    •   var  Dog = Class.create(); Dog.prototype = Object.extend( new  Animal(), { 
    •   initialize:  function (name) {    this.name  = name; this.sound =  "woof" ;  }  });
    • var  fido =  new  Dog( "Fido" );
    • fido.speak();
    • // -> alerts "Fido says: woof!"

×