Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the $$ (double dollar sign) used for in angular?

I'm taking a look at the angular 1.2 source code, and I'm just curious why some functions are prefixed with the two dollar signs. Is this some sort of convention?

like image 920
ThinkingInBits Avatar asked Oct 12 '13 19:10

ThinkingInBits


People also ask

What is the dollar sign used for in angular?

An Observable is a stream of values emitted over time. In code, it is often represented with the dollar sign $ as a suffix. For example, by using the fromEvent operator, we can create an observable that listen to changes to a DOM element element on input events.

What does double dollar sign mean?

The $$x (double dollar) is a reference variable that stores the value which can be accessed by using the $ symbol before the $x value.

What does dollar mean in typescript?

Updated on July 03, 2019. The dollar sign ($) and the underscore (_) characters are JavaScript identifiers, which just means that they identify an object in the same way a name would. The objects they identify include things such as variables, functions, properties, events, and objects.

How do you name observable?

If the observable is all about the side effect, name it like you might name a function. Give it a verb and noun combination that describes what it's doing, and what it's doing it to. performBounceAnimation$ , addButtonElement$ , updateAccountData$ , and so on. If the content is ambiguous, name it by intent.

What is $ $X (double dollar) in JavaScript?

The $$x (double dollar) is a reference variable that stores the value which can be accessed by using $ symbol before $x value. $x stores the value “Geeks” of String type.

What does $ $ (dollar dollar or double dollar) mean in PHP?

What does $$ (dollar dollar or double dollar) means in PHP ? The $x (single dollar) is the normal variable with the name x that stores any value like string, integer, float, etc. The $$x (double dollar) is a reference variable that stores the value which can be accessed by using $ symbol before $x value.

What does the dollar sign mean in jQuery variable names?

For easy access the jQuery library itself it is usually set up with the $ sign as an alias to it. The dollar sign is also often used as part of a variable name to denote that the variable contains a jQuery version of the object. Another place you may see it used as part of a variable name is in TypeScript,

What does the symbol $mean in angular?

The symbol $ is the prefix used by Angular for its own variables/properties. GG. GG. Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question.


2 Answers

  • Single $ for reserved, public identifiers
  • Double $$ for reserved private identifiers

To quote the docs:

$ Prefix Naming Convention

...

If you inspect a Scope, you may also notice some properties that begin with $$. These properties are considered private, and should not be accessed or modified.

like image 150
Doug T. Avatar answered Sep 28 '22 04:09

Doug T.


If I may add:

Angularjs Docs

Other than just being significant to Angularjs, the '$$' or '$' are just characters that are allowed in variable names. Angularjs uses both to identify significance for you and their own development team.

You could name all of your variables in the same way; but to avoid naming collisions, stay away from this practice. Here are some examples if you did...

$$$$myVariableName; $myVariableName$; _myVariableName_; $$$$$$myVariableName$$$$$$$$

Here is a link to test out JS variable names if you wish:

Variable Name Validator

Here is a link to MDN as well that explains allowed characters:

MDN allowed characters link

and here is the text:

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 identifiers.

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

Angulajs includes quite a bit of information in each object; some of the items are for Angularjs, and some are for the developer, which means that some may not be editable, but all should be available for reference if that is what you were going to use it for.

However, in future releases any private identifiers may disappear as the Angularjs team expects the developer not to use the reserved / private names.

In the case of the posted 'similar link' here is what Angularjs says:

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

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

If you inspect a Scope, you may also notice some properties that begin with $$. These properties are considered private, and should not be accessed or modified.

like image 21
SoEzPz Avatar answered Sep 28 '22 06:09

SoEzPz