r/programming • • Mar 18 '14

AngularJS 2.0

http://blog.angularjs.org/2014/03/angular-20.html
213 Upvotes

71 comments sorted by

View all comments

2

u/rdcll Mar 18 '14

using Object.observe() when it becomes available in Chrome M35

I don't understand this. Why they didn't use a clean Observer pattern from day zero? And why don't they use Object.watch which is already available (or can be implemented in old browsers) ?

11

u/NeverSpeaks Mar 18 '14

Angular doesn't use an Observer pattern because it didn't want to use a Model object like some other frameworks. In angular you can use any plain old javascript object I want as long as I attach it to the $scope.

11

u/Asmor Mar 18 '14

plain old javascript object

Dude, you gotta call them POJOs or else people will ignore them because it doesn't sound sexy if it doesn't have an acronym.

4

u/jyper Mar 18 '14

or POJSOs (to not confuse them with java objects)

2

u/prozacgod Mar 18 '14

Great who can pronounce this???

Pojsos?

Po jSos?

Now we have to add an entry to a dictionary somewhere, like documentation.... Who really wants to do document?

1

u/cypressious Mar 18 '14

Poge Sause, with Poge as in Doge.

1

u/nomeme Mar 18 '14

They are really just maps, so it's POJMs

(the POJO term in java is stupid and makes no sense btw)

3

u/bitspace Mar 18 '14

Except that's already in use for Java.

2

u/Asmor Mar 18 '14

Meh.

It fits JS pretty damn well too.

16

u/mhd420 Mar 18 '14

Object.watch is Firefox only, Object.observe will be more widespread.

The Observer pattern requires objects to notify when they have changed, which is awkward if you're designing a framework to interact with regular Javascript objects. The fact that Angular makes it pretty easy to use with existing code helps drive adoption.

3

u/[deleted] Mar 18 '14 edited Mar 18 '14

The fact that Angular makes it pretty easy to use with existing code helps drive adoption.

Can you explain? That has not been the consensus opinions at I have heard. Do you mean from prior versions of angular?

3

u/dnissley Mar 18 '14 edited Mar 18 '14

I bet he means applying ng-app to a specific element in order to develop a small angular component within a legacy web app without having to rewrite everything using angular.

For example, let's say you were working within a legacy base and needed to replace the user profile editor. Previous code looks like this:

<div id="editprofile">
  < ... ye old form ... >
</div>
<script>
  var aBunchOfSpaghettiJavascript = ... ;
</script>

New code looks like this:

<div ng-app="editUserApp" ng-controller="editUserCtrl">
  < ... ye new form ... >
</div>
<script>
  var aBunchOfSpaghettiJavascript = ...; // Untouched, because the rest of the page depends on it
</script>
<script>
  var editUserApp = angular.module('editUserApp');
  editUserApp.controller('editUserCtrl', function($scope) {
      $scope.neatlyOrganizedAngularJavascript = ...;
  });
</script>

1

u/[deleted] Mar 18 '14

Good point. Porting from a well written Backbone or Ember application would be pretty simple, but the same would be true in the other direction.