Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I don't consider myself a highly skilled javascript developer, but I thought I got one thing right for sure: don't create global variables unless you really have to.

I've been learning angularjs lately and discovered one strange thing, almost everywhere in code samples for angular you can find constructions like the following.

'use strict';

/* Controllers */

var phonecatControllers = angular.module('phonecatControllers', []);

phonecatControllers.controller('PhoneListCtrl', ['$scope', 'Phone',
  function($scope, Phone) {
    $scope.phones = Phone.query();
    $scope.orderProp = 'age';
  }]);

Source: official example app https://github.com/angular/angular-phonecat/blob/master/app/js/controllers.js

So I assumed I might be missing/misunderstanding something. Any thoughts except "since it's demo code, they don't care"?

share|improve this question
    
@kdgregory: you may consider promoting your comment to an answer, since it actually answers the question. –  MainMa May 2 at 19:28
    
@MainMa - done, although I think it would be better just to delete the question. –  kdgregory May 2 at 20:38

1 Answer 1

up vote 3 down vote accepted

It's demo code. If you want to read it from the Angular developers, go here and scroll down until you see

In practice, you will not want to have your controller functions in the global namespace.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.