简体   繁体   English

有人可以解释这个javascript(可能是angularJS)语法的含义吗?

[英]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.

相关问题 有人可以解释定义jQuery插件时的语法含义吗? - Can someone explain what the syntax means when defining a jQuery plugin? 有人可以解释一下这到底意味着什么吗? - Can someone please explain what this means exactly? 有人可以解释这个电子邮件正则表达式的含义 - Can someone explain what this Email regex means 有人可以用简单的英语解释在sankeyNetwork()中迭代参数的含义吗? - Can someone explain in plain English what the iterations argument means in sankeyNetwork()? 有人可以解释此代码示例中this.value的含义吗? - Can someone explain what this.value means in this example of code? Ruby on Rails和angularJS:有人可以解释用法和语法吗 - Ruby on Rails and angularJS: Can someone explain the usage and syntax pls 我是JavaScript新手。 有人可以向我解释这种语法在做什么()() - I'm new to JavaScript. Can someone explain to me what this syntax is doing ()() 有人可以解释这个高阶 JavaScript 函数令人困惑的语法吗? - Can someone explain this higher-order JavaScript function confusing syntax? 有人可以在JavaScript中解释这个函数包装语法吗? - Can someone explain this function-wrapping syntax in JavaScript? 有人可以从javascript帖子中解释以下摘录的含义吗? - Can somebody explain what below excerpt means from a javascript post?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM