Colon operator

I am trying to learn JavaScript. After reading this page: What does :: (colon) do in JavaScript?

I tried to replace

var store = new dojo.data.ItemFileReadStore({
         url: "countries.json"
 });

with

var store = new dojo.data.ItemFileReadStore();
        store.url = "countries.json";

This does not work. Can someone point out an error or explain the correct use of the Colon operator ?. Thank.

+3
source share
6 answers

This is not a fair comparison, although you are almost there.

var store = new dojo.data.ItemFileReadStore({
         url: "countries.json"
 });
//Creates a new store object, passing an anonymous object in with URL
// property set to "countries.json"

Alternative without a colon operator:

var props={};
props.url="countries.json"
var store = new dojo.data.ItemFileReadStore(props);
//Does same as above but doesn't use :

However, this is not the only use :in JavaScript, but it can also be used in the ternary operator ( alert(b==c?'equal':'not equal');) and in methods (for example, in operators case)

+9
source

url , - - , , , "url2".

url , , .

+2

.

, store. , , . . .

+1

. ItemFileReadStore, , , .

- , : =:

var options = {};

options.url = 'countries.json';

var store = new dojo.data.ItemFileReadStore(options);
0

, , , new dojo.data.ItemFileReadStore();, . , , .

: , , , , , FYI.

0
source

An object dojo.data.ItemFileReadStoreprobably requires a property urlat the time the object was created. If this is not the case, then the object does not allow you to set this property manually after you have already initialized the object.

The double is used in JSON to indicate the difference between a key and a value when you pass in the structure of an object ( {}).

0
source

All Articles