r/javascript • • Jul 10 '16

The JavaScript language reboot is done

https://medium.com/@velmu/the-javascript-language-reboot-is-done-7bcec4be2cb6#.dy2fyy9j1
41 Upvotes

98 comments sorted by

View all comments

3

u/lucidguppy Jul 10 '16

I'm afraid that the cycle will start again - and things will be reinvented.

Has anything really become simpler?

24

u/[deleted] Jul 10 '16

Has anything really become simpler?

Are you kidding me?

fetch('https://jsonplaceholder.typicode.com/posts').then(response => {
	if (response.status === 200) {
		response.json().then(data => {
			const filteredPosts = data.filter(obj => obj.userId === 1);
			console.log(`You have made ${filteredPosts.length} posts.`);
		});
	}
});

vs

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
	if (xhttp.readyState == 4 && xhttp.status == 200) {
		var posts = JSON.parse(xhttp.responseText);
		
		var filteredPosts = [];
		for (var i = 0; i < posts.length; i++) {
			var post = posts[i];
			if (post.userId === 1) {
				filteredPosts.push(post);
			}
		}
		
		console.log('You have made ' + filteredPosts.length + ' posts.');
	}
};
xhttp.open("GET", "http://jsonplaceholder.typicode.com/posts", true);
xhttp.send();

-6

u/constructivCritic Jul 10 '16 edited Jul 11 '16

So maybe just because I haven't learned about new method of doing things, but the xmlhttp version seems clearer to me.

EDIT: Whoever downvoted my comment...you're a dumbass for using the downvote button incorrectly. I was provoking some thought or some replies to better understand why the new way was better, I wasn't asking you to agree or disagree with me. Hiding my comment with downvotes detracts from the discussion... That's the opposite of what you want on a site like Reddit.

2

u/fzammetti Jul 10 '16

I for one agree with you. I think people are mistaking shortness and terseness for intrinsically better. Sometimes, more code is more expressive and the examples given here versus the older example, to my mind, bear that out.