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 12-03-2012, 06:47 PM   PM User | #16
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,454
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
filter() works in almost all browsers in common use and uses compiled processing built into the browser making it a lot faster as well as a lot shorter.

That you have to add a half dozen lines of extra code for the few browsers that don't yet support it that will add one extra comparison to what needs to run in the browsers that do makes your code easier to maintain than using a different way of coding. Once all browsers in use do support it you simply delete those extra lines of code.

Using an alternative approach just because one commonly used browser doesn't support it means that once that browser dies out you still have your far longer harder to maintain code waiting to be rewritten into something that is both a lot shorter and a lot faster.

If you want shorter easier to maintain code you'd use filter. That is is faster as well is a bonus.
__________________
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
Users who have thanked felgall for this post:
rnd me (12-03-2012)
Old 12-03-2012, 06:51 PM   PM User | #17
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,460
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
Quote:
Originally Posted by felgall View Post
If you want shorter, easier to maintain code you'd use filter. That it is faster as well is a bonus.
welcome to the future, may it serve you well!
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 12-03-2012, 08:02 PM   PM User | #18
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,454
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
Note that filter is also much shorter to code and test in the first place as you have only one line of code that you have written that needs testing as compared to the alternative where you have to write a lot more code including a loop.

You can easily implement filter for any of the browsers that do not yet support it by grabbing a copy of the code to add that support from the Mozilla JavaScript reference. You would not need to worry about testing that code any more than you'd need to worry about testing all the code in JQuery (if you use that JavaScript library) as the code has already been tested.


Why code and test an entire loop of code that needs to do the same thing as can already be easily done with only one line of new code.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/

Last edited by felgall; 12-03-2012 at 08:17 PM..
felgall 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 10:32 PM.


Advertisement
Log in to turn off these ads.