Going through some online resource I've came across these examples:
In this case this properties can be accessed via this.property
method and this['property']
, but can't be accesed using this[property]
function showFullName() {
alert( this.firstName + " " + this.lastName );
}
var user = {
firstName: "Alex",
lastName: "Graves"
};
showFullName.call(user)
In the following example accessing the properties using this.property
and this['property']
leads to undefined
.
var user = {
firstName: "Alex",
surname: "Graves",
secondSurname: "Martinez"
};
function showFullName(firstPart, lastPart) {
alert( this[firstPart] + " " + this[lastPart] );
}
showFullName.call(user, 'firstName', 'secondSurname')
Can you please clarify a bit the behavior of dot and square brackets?