Posted By

MMDeveloper on 10/17/08


Tagged

oop skeleton Framework


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

jamesming
sulfurito
shilguhn
ntulip
nerdfiles
seanpowell


javascript OOP skeleton


 / Published in: JavaScript
 

This is just a blank skeleton to show the syntax of the preferred method of writing JavaScript in an OOP manner; a JSON look and feel.

  1. var yourObjectName = {
  2.  
  3. property1: "some string",
  4. property2: 0,
  5. cities: new Array (
  6. "miami",
  7. "atlanta"
  8. ),
  9. states: ["florida", "georgia"],
  10. numbers: {
  11. 0,
  12. 1,
  13. 2
  14. },
  15.  
  16. method2: function(args) {
  17. return args;
  18. },
  19.  
  20. method3: function(args) {
  21. return this.method2(args);
  22. }
  23. };
  24.  
  25.  
  26. alert(yourClassName.property1);
  27.  
  28. alert(yourClassname.method2("send me back"));
  29. alert(yourClassname.method3("send me back"));

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: mongolito404 on October 20, 2008

Actually, this is not a class but rather an object with its very own properties and methods.

If the intend is to isolate the method and property to avoid name clashes and accidental overriding, you may be interested by the "module pattern" which is more complete (see http://yuiblog.com/blog/2007/06/12/module-pattern/)

Posted By: MMDeveloper on October 20, 2008

my mistake, snippet edited.

You need to login to post a comment.