I came across a code snippet in JS
globe =
{
country : 'USA',
continent : 'America'
}
Using the variable declared above by:
alert(globe.country);
Questions:
Thanks
That is a JS object with two properties.
Not using var
places the variable in the global scope
Though not a class, it can still have functions as properties
The functions can be tacked on two different ways:
globe.myFunc = function() { /* do something */ };
or
globe = {
...
myFunc: function() { /* do something */ }
}
That is a JavaScript object. Written in the object literal notation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With