Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 3 of 3 FirstFirst 123
Results 31 to 31 of 31
  1. #31
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Thanked 569 Times in 550 Posts
    first off, i didn't even look at the code, i was simply trying to show that function statements and expressions are almost identical in nature, and that expressions (especially those without local names) are not 'capable of a lot more' than statements. indeed, the code replaces those magical expressions with statements and seems to execute just fine. The code wasn't something i'd ever use, so i didn't give it my typical level of scrutiny, just enough scrutiny and firebug re-writing to show my function statement version in action. I don't care much for old IE, and I like to use inline (attrib-based) events for almost everything except grids, media events, and dnd handlers.

    My original main point here: always name your functions. I can see that if you tend to code more expressions than statements it can seem repetitive to use local names, but it's a good practice for several reasons i've already outlined.

    i will confess that i was fooled by the orig addEvent felgall posted. It looks like it sniffs the browser each time. That is doesn't is (to me) unexpected. I didn't pickup JS last night, so if something fools me, that speaks more the readability of the code than my literacy. Giving the anon functions names goes a long way toward readability. polymorhphism is fine for a compiler, but humans can only chunk so much, and that mental energy might be better spent on the logic, not the structure.

    i'm not saying there's anything wrong with the first code, it does what it's supposed to. I prefer a different style of function declaration. I think it results from differences in our individual programming approaches. Nothing wrong with that. You can use JS to write LISP or you can use it to write C, or even javascript...

    For the styles of programming i tend to use (data-centric functional, and event-driven), function statements plug-in nicely. A handy helper function can work much like Enums or constants instead of dot paths to make coding easier and cleaner. In conjunction with dependency injection, function statements encourage a readbility-enhancing flattening of the code, ameliorating the editor-crushing indentation problems that you see on a lot of async code using expressions and anon callbacks.

    As I moved away from classes, OOP and even protos, i came to appreciate function statements more. I can see that if you do a lot of OOP you might prefer expressions, since that's typically how methods are bound without repeating yourself. Most of the code i write os not verp OOPish. Myself, I rarely use the "new " operator, and within modules, i tend to publish what i public-ally need to exports in an admittedly repetitive block at the bottom of the module code, just above where i paste in all the utility function statements that support the module code that appears first-thing. i have used some fancy routines to "publish all functions as methods", but usually, it's simply a matter of poking through the few levers i need while keeping the gears oiled and the belts out of sight.
    Last edited by rnd me; 02-23-2013 at 06:31 AM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

Page 3 of 3 FirstFirst 123

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts