通过一些在线资源,我发现了这些例子:
在这种情况下可以通过this.property
方法和this['property']
访问此属性,但无法使用this[property]
function showFullName() {
alert( this.firstName + " " + this.lastName );
}
var user = {
firstName: "Alex",
lastName: "Graves"
};
showFullName.call(user)
在以下示例中,使用this.property
和this['property']
访问属性会导致undefined
。
var user = {
firstName: "Alex",
surname: "Graves",
secondSurname: "Martinez"
};
function showFullName(firstPart, lastPart) {
alert( this[firstPart] + " " + this[lastPart] );
}
showFullName.call(user, 'firstName', 'secondSurname')
你能否澄清点和方括号的行为?