OOJS - Object Oriented Javascript pt 2


/ Published in: JavaScript
Save to your folder(s)

using prototype to add instance methods to a Class


Copy this code and paste it in your HTML
  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()

URL: oojs

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.