Posted By

reelfernandes on 03/20/11


Tagged

javascript object oriented OOJS


Versions (?)

OOJS - Object Oriented Javascript


 / Published in: JavaScript
 

URL: oojs

  1. var a = MyClass()
  2. a.name = "I'm A"
  3. a.init()
  4.  
  5. var b = MyClass()
  6. b.name = "I'm B"
  7. b.init()
  8.  
  9. alert( a.name+", "+b.name )
  10.  
  11. function MyClass()
  12. {
  13. var myObject = {}
  14. myObject.init = com_myclass_init
  15. myObject.name = ""
  16. return myObject
  17. }
  18.  
  19. // simulate namespaces & avoid nesting object methods
  20. function com_myclass_init()
  21. {
  22. alert( this.name )
  23. }

Report this snippet  

You need to login to post a comment.