Posted By

dbug13 on 08/27/08


Tagged

javascript textmate


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

xuanyan
koncept


Basic Object extending


 / Published in: JavaScript
 

  1. function BaseClass(extended_props){
  2. this.extend = function(props){
  3. for(var i in props){
  4. this[i] = props[i]
  5. }
  6. }
  7.  
  8. if(extended_props){
  9. this.extend(extended_props);
  10. }
  11.  
  12. if(this.init){
  13. this.init();
  14. }
  15. }
  16.  
  17. var Foo = new BaseClass({
  18. name: "Jamie Allison",
  19. init: function(){
  20. alert("Called from Foo.init()");
  21. }
  22. });
  23.  
  24. Foo.extend({
  25. age: 32
  26. });
  27.  
  28. alert("Age is: " + Foo.age);

Report this snippet  

You need to login to post a comment.