Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-18-2007, 11:04 PM   PM User | #1
snoodle
Regular Coder

 
Join Date: May 2007
Location: Manteca, CA
Posts: 219
Thanks: 4
Thanked 0 Times in 0 Posts
snoodle is an unknown quantity at this point
Javascript OOPs

I realize that strictly speaking javascript doesn't support OOP's constructs (like class) but I've been reading about all these methods of coercing javascript to be an object oriented language.

I'm building a javascript table builder and am toying with doing it in one of these suggested ways, but I'm wondering if it makes any sense. The syntax gets a little weird and cumbersome at times and I'm not sure you really get all the gains of a pure OOP's language.

Also, even my procedural javascript files are pretty OOPsy, with a single js file representing a class. The main consideration would be to be able to have more than one table on a page. But then, a table element is already an instance of an object, so I could be passing the element to my "methods" and achieve the same thing. Anybody have any thoughts on the matter? Does it pay to try to make javascript behave like a true OOPs language?
snoodle is offline   Reply With Quote
Old 06-19-2007, 04:50 AM   PM User | #2
TNO
Regular Coder

 
Join Date: Apr 2005
Posts: 213
Thanks: 2
Thanked 1 Time in 1 Post
TNO is an unknown quantity at this point
I've always considered ECMAScript in general to be OOP:

http://www.crockford.com/javascript/

I can understand how it can be confusing if you come from a stricter OOP language, but I consider the dynamics of this language (and its cousins) to be more expressive and powerful in general.
TNO is offline   Reply With Quote
Old 06-19-2007, 06:17 AM   PM User | #3
snoodle
Regular Coder

 
Join Date: May 2007
Location: Manteca, CA
Posts: 219
Thanks: 4
Thanked 0 Times in 0 Posts
snoodle is an unknown quantity at this point
im in the midst of a coding frenzy, but i'll be sure and check out ECMAScript. Right now I settled on just using an element as an object and passing in the elem reference to every "pseudo" method. its kind of nice that you can just throw new members into an element, and javascript function pointers are working out nicely... so the code is pretty clean and best of all - its working. in one day i put together a table gizmo that rivals that $400 Active Widget deal.
snoodle is offline   Reply With Quote
Old 06-19-2007, 10:00 AM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,452
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
JavaScript is a prototype based OOP rather than a class based OOP. All it means is that you have a lot more flexibility than with a normal class based OOP because there is no distinction between classes and objects and you can easily add properties and methods dynamically to an already existing object or group of objects all based on the same prototype (not that you necessarily would, conventional OOP as you would have with regular classes is also possible and more useful in most instances).
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 06-21-2007, 06:06 PM   PM User | #5
snoodle
Regular Coder

 
Join Date: May 2007
Location: Manteca, CA
Posts: 219
Thanks: 4
Thanked 0 Times in 0 Posts
snoodle is an unknown quantity at this point
yeah, i ended up going with the standard javascript oops method, using "prototype" for methods and all that. writing the "classes" themselves is a bit of annoying but using the class is nice.

one question while i'm on the subject...
if you have elements as memebers within your object and it comes to disposal time, i've read you removechild for each element, but do you "delete" the element itself? don't recall seeing anything about that.

so do free up an instance of a class, i would have something like dispose(obj) and dispose would free up each of it's members (that are, themeselves, objects) and then finally "delete" the object instance, itself. does that sound right? and again, do i need to delete element?
snoodle is offline   Reply With Quote
Old 06-21-2007, 09:05 PM   PM User | #6
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,455
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
unless you are not refreshing the page all day, don't worry too much about deleting elements.

JS does it's own internal garbage collection, and if you're avoiding unnecessary closures,( which it sound like you are), you have nothing to worry about.

you could also do all your 'heavy lifting' in a hidden iframe, pushing the results to top.document, and periodically, invisibly refresh the iframe.
rnd me is offline   Reply With Quote
Old 06-22-2007, 05:12 AM   PM User | #7
snoodle
Regular Coder

 
Join Date: May 2007
Location: Manteca, CA
Posts: 219
Thanks: 4
Thanked 0 Times in 0 Posts
snoodle is an unknown quantity at this point
yeah, i wasn't thinking. i guess as long as it's a child, the browser will take care of cleanup. i'm really putting in the hours these days and making some dumb mistakes. i'll be taking a much needed 2 week break in a few weeks. i think my machine needs a break from me as well.
snoodle is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:02 PM.


Advertisement
Log in to turn off these ads.