[英]Can someone explain what this javascript (possibly angularJS) syntax means?
Currently learning AngularJS.目前正在学习 AngularJS。 This was given as an example:
这是一个例子:
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
controller: 'HomeController',
templateUrl: 'views/home.html'
})
.otherwise({
redirectTo: '/'
});
});
I don't understand this syntax of beginning the line with a property (ie .when
or .otherwise
. What object are these properties linked to? I'm assuming its $routeProvider
, but two properties are being called it seems, and ive never seen properties accessed on a different line than the object. what does the entire structure of code mean? It's completely foreign to me. Is this an angularJS thing or did I learn javascript way too fast?我不明白开头的行与属性(即此语法
.when
或.otherwise
,在这些属性相关联?我假设它是什么物体$routeProvider
,但两个属性被称为似乎和我从来没有看到在与对象不同的行访问的属性。代码的整个结构是什么意思?对我来说完全陌生。这是 angularJS 的事情还是我学 javascript 的速度太快了?
它会调用$routeProvider
上的when
方法, $routeProvider
不是调用when
调用结果的otherwise
方法( when
将返回$routeProvider
- 它被称为Fluent Interface )。
It's basic JavaScript syntax.这是基本的 JavaScript 语法。 The
.when()
and .otherwise()
are just function calls via property references. .otherwise()
.when()
和.otherwise()
只是通过属性引用进行的函数调用。 The fact that there are two of them just means that .when()
returns an object, and probably the $routeProvider
object itself.其中有两个的事实只是意味着
.when()
返回一个对象,可能还有$routeProvider
对象本身。 Thus, the return value from .when()
can be used to invoke another method on the same object.因此,
.when()
的返回值可用于调用同一对象上的另一个方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.