Hi,
> >> This could be written using no variable as:
> >> $('<div/>').appendTo('body')
>
> > I think this is just an example of a smart refactoring.
No it is not.
> >> Or even as:
>
> >> $('<div/>').text('content').appendTo('body').click(function(){alert('clicked:
> >> ' + $(this).text())})
There is a reason why Java is so important today in "professional
programming". When you have (sometimes very large) teams of
programmers (of all types - and quality!) working on projects for
years, when code has to go through many hands (over time and through
departments or even companies), often with changing programmers, you
have to have a different style.
Apart from the problem that if any one part of such a chain fails it's
harder to find out WHICH part did so compared to having it all on a
single line, it simply isn't as readable (whatever you say, that's a
psychologically proven fact) - unless you have very little code.
Of course, when JS is used only for adding a little interaction to a
page - go ahead like this. However, when you write a application I'd
fire you instantly before you create even more chaos to be untangled
later by others trying to debug your code :-) For example, in such
projects I want to have the code that binds behavior to the UI in one
place - but the actual functions doing that job in quite another, so
no anonymous functions right inside the .click(....), ever.
Readability for large pieces of code would be impacted severely
otherwise.
Michael
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.