此摘要有什么问题? (JavaScript对象)

时间:2019-05-12 15:43:01

标签: javascript object

const address = {
	street: 'Dique 3',
	city: 'Santa Cruz',
	zipcode: 38320,
	function showAddress {
		console.log(`${this.street}, ${this.city}, ${this.zipcode}`)
	}
}

address.showAddress();

1 个答案:

答案 0 :(得分:1)

您添加方法的方式错误。

const address = {
	street: 'Dique 3',
	city: 'Santa Cruz',
	zipcode: 38320,
	showAddress(){
		console.log(`${this.street}, ${this.city}, ${this.zipcode}`)
	}
}

address.showAddress();