Это в функции внутри объекта Javascript - PullRequest
0 голосов
/ 05 февраля 2019

что не так в этом коде, функция fullAdress Я не знаю, что не так в моем коде, помогите исправить это

var person = {
	firstName: 'Ammar',
	lastName: 'Gais',
	age:21,
	adress:{
		street:'king road',
		city:'atabra',
		state:'River Nile'
		fullAdress: function(){
			return this.street+" "+this.city+" "+this.state;
		}
	},
	fullName: function() {
		return this.firstName+" "+this.lastName;
	}
}

1 Ответ

0 голосов
/ 05 февраля 2019

Вы пропустили запятую после 'River Nile'.Всегда рекомендуется заглядывать в консоль браузера на наличие таких ошибок.Даже у объекта есть свойства или методы, все должно быть разделено запятой:

var person = {
  firstName: 'Ammar',
  lastName: 'Gais',
  age: 21,
  adress: {
    street: 'king road',
    city: 'atabra',
    state: 'River Nile',
    fullAdress: function() {
      return this.street + " " + this.city + " " + this.state;
    }
  },
  fullName: function() {
    return this.firstName + " " + this.lastName;
  }
}

console.log(person.adress.fullAdress());
console.log(person.fullName());
...