PDA

View Full Version : Some clarifications needed



BubikolRamios
Dec 30th, 2013, 01:15 AM
This is working code, need some explanations how to read it ...


var e, t, n = this;
for (e in this.mapData.paths)'1't = this.canvas.addPath
(
{
'2'd: this.mapData.paths[e].path,"data-code": e

....


Red things inserted by me.

1. should not there be '{' ?
And since it is not what is all that doing ?

2. how to read that entire line, what are ":" doing ?

DaveyErwin
Dec 30th, 2013, 02:44 AM
Well as for number two ...



<script>
function displayPropertyValues(object){
for(property in object)
alert(property+" = "+object[property]);
}
displayPropertyValues({one:1,two:2}) 
</script>


{} creates an object
{one:1,two:2} creates an object and
adds properties and sets their values
it is called an object literal

BubikolRamios
Dec 30th, 2013, 03:11 AM
OK, but then as for 2



d: this.mapData.paths[e].path,"data-code": e

This looks strange tome, should be then without " ?

felgall
Dec 30th, 2013, 03:42 AM
OK, but then as for 2



d: this.mapData.paths[e].path,"data-code": e

This looks strange tome, should be then without " ?

The " are optional where the property name complies with the standards for naming variables - that is it starts with a letter, _ or $ and only contains letters, numbers _ and $ but the " can always be included when using that notation. They are mandatory if passing data that way between the browser and the server.

With your first query the {} are not needed when they only contain a single statement. It is still better to put them there though.