Author |
Message |
wtd
|
Posted: 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

|
|
 |
Clayton

|
Posted: 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  |
|
|
|
|
 |
wtd
|
Posted: 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.
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

|
Posted: 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  |
|
|
|
|
 |
wtd
|
Posted: 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

|
Posted: 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
|
Posted: 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.  |
|
|
|
|
 |
|