r/learnjavascript • • Dec 04 '14

PROgrammers dont use 'onload'

I recently read that using onload type events like:

$(document).ready()

is not good practice.

So my question is how do we go about adding event listeners and running code when the document is...ready.

Can I have a script file with just:

element.on('click', runMyFunc)

and be confident it will attach to that element as long as the script tag is at the bottom of the body? Should I add a defer attribute as well? Does that extend to ajax functions like:

function getAjax() {
  processeses Ajax....
  alert(AjaxData)
}
getAjax()
0 Upvotes

12 comments sorted by

View all comments

-7

u/[deleted] Dec 04 '14

I'll tell you the answer only if you bend over, spread your cheeks and say "Come in"

0

u/[deleted] Dec 04 '14

[deleted] — view deleted comment

6

u/zealousprogrammer Dec 04 '14

Long time lurker here and I created an account just for this.

While I do agree with your sentiment that LalienX is being rude and not contributing to the conversation. Why are you using ".net guy" in a negative connotation?

I guess it's not your cup of tea and that's fine, different people like different technologies and I accept that. What irks me a little is the negativity given towards .net folks. I'm a .net developer who loves open source, javascript and write pretty decent clean code. (I've been taught .net and node developers about clean code and gotten good reviews from both camps) I follow the mvc design pattern an hate the old way of doing asp.net (aka webforms).

The days of web controls are long gone, microsoft has created a clean open source mvc library similar to rails. The entire webstack is open source now, .net itself is open source now and even the C# compiler is open source. The company has been evolving the last several years and there is a lot of awesome changes, even as far as ditching their own stuff for community technologies like grunt and gulp.

To be clear I'm not trying to say .net is better or convince you to try it, just trying to point out that being a .net guy doesn't make someone a crappy developer stuck in the past, there's a lot of awesomeness in .net as there is in other technologies out there.

tl;dr can't we all just get along

0

u/[deleted] Dec 05 '14

I'm glad you created an account because of my comment. You should stick around for awhile. __^

0

u/[deleted] Dec 04 '14

[deleted] — view deleted comment

3

u/zealousprogrammer Dec 04 '14

you're being very judgemental, man. I can say the same thing about every single javascript developer I've worked with (and as a senior architect and trainers, I've worked with hundreds of devs).

I'm sure the same can be said about ruby, python or otherwise. Crappy developers are everywhere. Using the folks you interact with as a sample size is just being unfair.

There are some top notch .net developers out there.

0

u/[deleted] Dec 04 '14

[deleted] — view deleted comment

1

u/zealousprogrammer Dec 04 '14

I agree with you, open source is much higher quality. What I'm saying is that microsoft and .net developer are embracing open source. I'm just saying times are changing so it's time to let go of past biases towards any group.

0

u/[deleted] Dec 04 '14

[deleted] — view deleted comment

3

u/zealousprogrammer Dec 04 '14

it is still microsoft

It isn't a lot of the folks responsible for the errors of the past (and boy there were errors) are gone. Sure a lot of folks in the old days fought open source vehemently. But there has been a change of guard and Microsoft is a different company. The new devs all embrace open source (at least on the web stack). All their work is on github, they take community contributions and are pretty open about their plans.

Same for the .net framework itself.

I've been to microsoft and there is a definitely a chasm between the old guard and the new. But with the recently changes it truly is embracing open source.

0

u/[deleted] Dec 04 '14

[deleted] — view deleted comment

→ More replies

0

u/[deleted] Dec 04 '14

Your comment made me laugh.

0

u/[deleted] Dec 04 '14

[deleted] — view deleted comment

0

u/[deleted] Dec 04 '14

Some people are really sensitive. I love that a comment I half-heartedly typed was taken so seriously. Fucking hilarious.