What Means Two Keys in Javascript

Asked

Viewed 720 times

12

I understood the "===" that tests value and type, different from the "==" that tests only value, but I didn’t understand the double key, type: {{alguma_coisa}}, for example in a Javascript that I have, have something like this:

mozL10n.get('page_of', {pageCount: pagesCount}, 'de {{pageCount}}');

There is even the need for two keys?

  • It seems to be the notation of some framework, perhaps Angularjs

  • 1

    "l10n" means to localization, related article: http://www.w3.org/International/questions/qa-i18n#l10n

2 answers

14


This is specific to this Non-standard API. Avoid using it.

Is a placeholder. It is used to produce an interpolation of string, although it uses a simpler form. It is very similar to the {0} used in C#, but a little better because the expression can be used inside the string, as in the interpolation of string of the C#. This expression will be evaluated and the result will be printed at this location.

The double keys were chosen to avoid any ambiguity, it could be anything else. The important thing is to have some character that marks the beginning and end of the expression and that is something little used in normal texts, to avoid having to escape and print this normally.

  • It is worth adding that in ECMA Script 6 there will be a similar standard feature, but with different syntax. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings

8

In this example:

var a = {};
console.log(a);

It is only used to initialize an object with no value in it.

In his Example:

mozL10n.get('page_of', {pageCount: pagesCount}, 'de {{pageCount}}');

It is used as a standard template for identification of values that will be modified, this is not javascript, but a convention of your API.

  • I understood both, Gabriel and Bigown. A placeholder as said the bigown.

  • 1

    Which is replaced by a value ok, what I was not understanding is the use of two keys, I thought it might be some novelty in newer versions of javascript.

  • @pnet it is interesting that you specify which framework you are using so that we can respond more specifically, at least in the new ES6 javascript there is nothing new about it.

  • Have you answered the double key ratio.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.