SitePoint Sponsor |
|
User Tag List
Results 1 to 14 of 14
Thread: OOP or Not?
-
Aug 23, 2003, 20:48 #1
- Join Date
- Jul 2003
- Location
- Sacramento, CA
- Posts
- 330
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OOP or Not?
I have heard alot of people call JavaScript an Object Oreinted Language! And others say not? Yet alot of times when I write a function it seems almost procedural in nature?
-
Aug 23, 2003, 23:33 #2
- Join Date
- Aug 2002
- Location
- Burpengary, Australia
- Posts
- 4,495
- Mentioned
- 0 Post(s)
- Tagged
- 1 Thread(s)
It is procedural code, but an object-based language. Take this code for example
Code:var oTextarea; function alertTextarea ( ) { oTextarea = document.getElementById('textarea'); alert(oTextarea.Value); }
-
Aug 24, 2003, 14:16 #3
- Join Date
- Mar 2002
- Location
- Manchester, UK
- Posts
- 853
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
From what I've seen, it's sort of a hybrid.
You can define and manipulate objects, but it's usually used in a procedural way. I've no idea whether it's possible to define methods on an object, though I wouldn't be surprised if it was. And if you can do that, then it's capable of full OO, even if that capability is rarely used.gav
http://www.livejournal.com/users/blufive/
browser stats analysis and comment:
http://www.livejournal.com/community/stats_weenie/
-
Aug 24, 2003, 19:50 #4
- Join Date
- Jan 2003
- Location
- Calgary, Canada
- Posts
- 2,063
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
you can define methods using the following:
Code:object.method = function(var1, var2) { alert(var1 + var2); }; object.method(1, 6);
Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.
-
Aug 24, 2003, 20:09 #5
- Join Date
- Jul 2003
- Location
- Sacramento, CA
- Posts
- 330
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yes Yes But how can it be both Object and Procedural Based?
-
Aug 25, 2003, 07:30 #6
- Join Date
- Jan 2003
- Location
- Calgary, Canada
- Posts
- 2,063
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The same way PHP can. You can write OOP and Procedural code with it, however in Javascript, everything is based on behind-the-scenes objects, even when working with procedural code.
Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.
-
Aug 25, 2003, 07:33 #7
What Jeff said. At worst, Javascript is an object-based procedural language, similar to Visual Basic in nature. At best, it's object-oriented. Like PHP though, it's up to you which way you want to go with it.
-
Aug 25, 2003, 08:11 #8
- Join Date
- Dec 2002
- Location
- Alabama, USA
- Posts
- 2,560
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Everyone is correct, but I know that sounds contradictory
Excerpts from the Netscape Javascript Guide:
"JavaScript is an object-based language based on prototypes, rather than being class-based."
"Class-based object-oriented languages, such as Java and C++, are founded on the concept of two distinct entities: classes and instances.
...
A prototype-based language, such as JavaScript, does not make this distinction: it simply has objects. A prototype-based language has the notion of a prototypical object, an object used as a template from which to get the initial properties for a new object. Any object can specify its own properties, either when you create it or at run time. In addition, any object can be associated as the prototype for another object, allowing the second object to share the first object's properties."
-
Aug 25, 2003, 08:27 #9
- Join Date
- Jan 2003
- Location
- Calgary, Canada
- Posts
- 2,063
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Good excerpts there, Mike
Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.
-
Aug 25, 2003, 08:42 #10
- Join Date
- Dec 2002
- Location
- Alabama, USA
- Posts
- 2,560
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks, Jeff. The Netscape Javascript Reference and Guide are my best buddies
-
Aug 25, 2003, 08:49 #11
- Join Date
- Jan 2003
- Location
- Calgary, Canada
- Posts
- 2,063
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I've got my full Javascript for Netscape 3.0 book, lol.
Who walks the stairs without a care
It shoots so high in the sky.
Bounce up and down just like a clown.
Everyone knows its Slinky.
-
Aug 25, 2003, 10:55 #12
Originally Posted by Jeff Lange
Good fodder for the fireplace in the winter?
-
Aug 25, 2003, 11:18 #13
- Join Date
- Dec 2002
- Location
- Alabama, USA
- Posts
- 2,560
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Aug 25, 2003, 15:28 #14
- Join Date
- Jul 2003
- Location
- Sacramento, CA
- Posts
- 330
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I should burn my JS bible I learn more from forums!
Bookmarks