gpt4 book ai didi

javascript - AngularJS中$和$$的区别

转载 作者:行者123 更新时间:2023-12-02 16:35:57 25 4
gpt4 key购买 nike

我正在使用

$scope.$on('$routeChangeStart', function (event, toState, toParams, fromState, fromParams)     
{
//content
$log.log(toState);
}

跟踪我正在导航的路线。当我打印“toState”时,它给了我一个对象,如下所示。

{
$$route: Object
loadedTemplateUrl: "views/homepage.html"
locals: Object
params: Object
pathParams: Object
scope: ChildScope
__proto__: Object
}

在这里,我对“$$route”中的“$$”不是 100% 确定。有人可以解释一下 $ 和 $$ 之间的区别吗?

最佳答案

也许我们可以添加 Jiří Pospíšil 包含的链接:

Similar Link

除了对 Angularjs 有意义之外,“$$”或“$”只是变量名称中允许使用的字符。 Angularjs 使用两者来确定对您和他们自己的开发团队的重要性,如“类似链接”中所述。

您可以用相同的方式命名所有变量;但为了避免命名冲突,请远离这种做法。如果您这样做的话,这里有一些示例...

$$$$myVariableName; $myVariableName$; myVariableName; $$$$$$myVariableName$$$$$$$$

如果您愿意,这里有一个测试 JS 变量名称的链接:

Variable Name Validator

这里还有一个 MDN 链接,解释了允许的字符:

MDN allowed characters link

这是文本:

Variables

You use variables as symbolic names for values in your application. The names of variables, called identifiers, conform to certain rules. A JavaScript identifier must start with a letter, underscore (_), or dollar sign ($);

subsequent characters can also be digits (0-9). Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z"(lowercase).

Starting with JavaScript 1.5, you can use ISO 8859-1 or Unicode letters such as å and ü in identifiers. You can also use the \uXXXX Unicode escape sequences as characters in ientifiers.

Some examples of legal names are Number_hits, temp99, and _name.

Angulajs 在每个对象中包含相当多的信息;有些项目适用于 Angularjs,有些项目适用于开发人员,这意味着有些项目可能不可编辑,但如果您打算使用它,则所有项目都应该可供引用。

但是,在未来的版本中,任何私有(private)标识符都可能会消失,因为 Angularjs 团队希望开发人员不要使用保留/私有(private)名称。

更新:深入研究其中一些私有(private)标识符也可能会加深人们对 Angularjs 的理解;可以这么说,在幕后。

对于发布的“类似链接”,Angularjs 是这么说的:

$ Prefix Naming Convention You can create your own services, and infact we will do exactly that in step 11. As a naming convention,Angular's built-in services, Scope methods and a few other AngularAPIs have a $ prefix in front of the name.

The $ prefix is there to namespace Angular-provided services. Toprevent collisions it's best to avoid naming your services and modelsanything that begins with a $.

If you inspect a Scope, you may also notice some properties that beginwith $$. These properties are considered private, and should not beaccessed or modified.

关于javascript - AngularJS中$和$$的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27927985/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com