r/javascript • • Jun 09 '16

jQuery 3.0 Final Released

https://blog.jquery.com/2016/06/09/jquery-3-0-final-released/
229 Upvotes

52 comments sorted by

View all comments

Show parent comments

0

u/[deleted] Jun 09 '16

[deleted]

1

u/2Punx2Furious Jun 09 '16

bind your model and your view so that when your model changes, the view reflects those changes automatically

handle routing

Could you please expland on these a bit more? I did the Angular course on codecademy, but at the end of it I was very confused.

What's model and view? What is routing?

16

u/snarkyturtle Jun 09 '16

With jQuery, updating something would be akin to doing something like:

$('.content').text('Content')

this is well and dandy until you have a ton of fields to update

$('.firstname').text('John')
$('.lastname').text('Doe')
$('.address').text('123 Fake St')
$('.phone').text('1231231234')

What MV* solutions allow you to do is declare a model in a .js file and use binding to do what all the $.text calls would do:

// main.js
$scope.person = {
  firstname: 'John',
  lastname: 'Doe',
  address: '123 Fake St',
  phone: 1231234
}

// index.html
<div>
  <p> {{person.firstname}} </p>
  <p> {{person.lastname}} </p>
  <p> {{person.address}} </p>
  <p> {{person.phone}} </p>
</div>

Now the best part is that you're probably fetching this from the database so you could just fetch json from the server and pass that to the model like so:

// main.js
$.getJSON('/person/find/1').then(function(person) {
  $scope.person = person
})

The best part of using the Model View paradigm is that you can add models/fields with minimal changes to the code. Just add that to your backend and your view and you're good to go.

1

u/2Punx2Furious Jun 09 '16 edited Jun 09 '16

Oh, I see, it looks very useful. Is that Ember or Angular?

It kind of reminds me of other Object Oriented programming languages.

3

u/[deleted] Jun 10 '16

[removed] — view removed comment

4

u/azium Jun 10 '16

It doesn't have to be OOP though.. you can achieve model -> view bindings in a purely functional world.

4

u/vinnl Jun 10 '16

In fact, that's what React largely does. It doesn't feel similar to Angular at all...

1

u/2Punx2Furious Jun 10 '16

Which one do you recommend to start with? I started with Angular, but I didn't like it very much.

2

u/[deleted] Jun 10 '16

[removed] — view removed comment

4

u/kescusay Jun 09 '16

That's angular.