Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How JavaScript treats lines starting with a dot?

I try to understand the examples on angularjs.org. For example the following code snippet. How does this .value and .factory and .config work?

angular.module('project', ['ngRoute', 'firebase'])

.value('fbURL', 'https://angularjs-projects.firebaseio.com/')

.factory('Projects', function($firebase, fbURL) {
  return $firebase(new Firebase(fbURL)).$asArray();
})

.config(function($routeProvider) {
  ...

EDIT:

My point of not understanding the code above is the blank line after the first line and the line starting with a dot.

like image 567
hol Avatar asked Dec 02 '22 18:12

hol


1 Answers

As standard dictates, unless there's a reason for ASI (like using postfix op, return, continue, throw or break statements), line terminators that separate language tokens are treated by JS as any other whitespace - that is, ignored. So these lines...

angular.module(arg1, arg2)
.value(arg3)
.controller(arg4)
.filter(arg5)

... are treated essentially the same as ...

angular.module(arg1, arg2).value(arg3).controller(arg4).filter(arg5)

So it's all about readability.

like image 181
raina77ow Avatar answered Dec 22 '22 08:12

raina77ow