Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Javascript] A little bit of OOP for the day
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic
Author Message
wtd




PostPosted: Sun Nov 12, 2006 5:26 pm   Post subject: [Javascript] A little bit of OOP for the day

code:
<html>
<head>
   <script>
      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);
   </script>
</head>
<body>
   <script>document.write(foo);</script>
   <script>document.write(bar);</script>
</body>
</html>
 
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Mon Dec 04, 2006 7:57 pm   Post subject: (No subject)

So basically, Javascript is Java in an HTML body?

I don't really understand what's going on, so please feel free to elaborate Razz
 
wtd




PostPosted: Mon Dec 04, 2006 7:59 pm   Post subject: (No subject)

Javascript is a language which has nothing to do with Java, and yes, it can be embedded into HTML. Smile

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




PostPosted: Mon Dec 04, 2006 8:03 pm   Post subject: (No subject)

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 Razz
 
wtd




PostPosted: Mon Dec 04, 2006 8:08 pm   Post subject: (No subject)

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




PostPosted: Mon Dec 04, 2006 10:19 pm   Post subject: (No subject)

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




PostPosted: Mon Dec 04, 2006 11:29 pm   Post subject: (No subject)

Dynamic typing, first class functions, prototype-based OOP...

Yeah, it's a bit different from Java. Wink
 
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh pageAdd this topic to your bookmarks (CTRL-D) View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: