Posted By

reelfernandes on 03/20/11


Tagged

javascript object oriented OOJS


Versions (?)

OOJS - Object Oriented Javascript pt 2


 / Published in: JavaScript
 

URL: oojs

using prototype to add instance methods to a Class

  1. function MyClass( name )
  2. {
  3. this.name = name
  4. }
  5.  
  6. MyClass.prototype.init = function()
  7. {
  8. alert( "I'm "+this.name )
  9. }
  10.  
  11. var a = new MyClass( 'A' );
  12. var b = new MyClass( 'B' )
  13.  
  14. a.init()
  15. b.init()

Report this snippet  

You need to login to post a comment.