
-----------------------------------
wtd
Sun Nov 12, 2006 5:26 pm

[Javascript] A little bit of OOP for the day
-----------------------------------


   
      function Foo(bar) {
         this.bar = bar;

         this.toString = function() {
            return this.bar.toString() + "!";
         }
      }

      function Bar(bar) {
         this.prototype = new Foo(bar);
         
         this.toString = function() {
            return this.prototype.toString() + "!";
         }
      } 

      var foo = new Foo(42);
      var bar = new Bar(27);
   


   document.write(foo);
   document.write(bar);



-----------------------------------
Clayton
Mon Dec 04, 2006 7:57 pm


-----------------------------------
So basically, Javascript is Java in an HTML body?

I don't really understand what's going on, so please feel free to elaborate :P

-----------------------------------
wtd
Mon Dec 04, 2006 7:59 pm


-----------------------------------
Javascript is a language which has nothing to do with Java, and yes, it can be embedded into HTML.  :)

What's going on here is the definition of two "classes".  This is interesting because Javascript is a prototype-based language, and has no classes.

-----------------------------------
Clayton
Mon Dec 04, 2006 8:03 pm


-----------------------------------
So... what exactly is Javascipt used for? I imagine for some sort of web development, but is there anything else? What are the pros and cons? Just asking some questions here :P

-----------------------------------
wtd
Mon Dec 04, 2006 8:08 pm


-----------------------------------
Yes, Javascript is used for things other than web development.  It can be used as a general purpose programming language.  Mozilla makes heavy use of it for variuos purposes in Firefox and Thunderbird.  Microsoft supports scripting Windows machines with Javascript.  I'm pretty sure ActionScript is just Javascript by another name, and is used for scripting Flash applications.

-----------------------------------
bugzpodder
Mon Dec 04, 2006 10:19 pm


-----------------------------------
i recently started to use a bit js for client side scripting, and i was shocked at its versatility and how different it is from java...

-----------------------------------
wtd
Mon Dec 04, 2006 11:29 pm


-----------------------------------
Dynamic typing, first class functions, prototype-based OOP...

Yeah, it's a bit different from Java.  ;)
