1

I'm looking at this code that someone else wrote. This looks to me like a bad code smell. What could be a valid reason to copy a reference to angular under the $rootScope?

    $rootScope._ = $window._;
    $rootScope.angular = $window.angular;
Chris Halcrow
  • 28,994
  • 18
  • 176
  • 206
  • 2
    this looks like someone either trying to change angular's behaviors in some way or trying to do something that angular isn't natively designed to do, and in either case, I wouldn't trust the code. Frankly, my view is that **any** use of `$rootScope` is probably a shortcut with a more sound solution available. – Claies Apr 05 '17 at 00:27

1 Answers1

1

As a rule of thumb, it's generally bad to assign anything to $rootScope in AngularJS. It's like assigning a global variable in most languages -- when you find yourself doing it, you should probably stop to think if there's another way to solve your problem. They tend to make code messy and impossible to follow.

This on the other hand... this is just extra weird, and is most definitely a bad code smell. I can't see a single valid reason why you would throw an already globally accessible variable on $rootScope, especially throwing angular itself onto $rootScope.

Ben
  • 2,441
  • 1
  • 12
  • 16