OOJS - Object Oriented Javascript


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



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

URL: oojs

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.