Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   массив объектов (https://javascript.ru/forum/misc/42096-massiv-obektov.html)

Anna77 13.10.2013 15:12

может так?
function Person(name,surname,age) {
this.name = name;
this.surname = surname;
this.age = age;
this.who = function who(){
document.write("<tr><td>" + this.name + "</td><td>" + this.surname + "</td><td>" + this.age + "</td></tr>" );
}

BETEPAH 13.10.2013 15:25

Да оставьте в покое document.write!
К тому же
Цитата:

Сообщение от Anna77
вывода таблицы при помощи созданного самостоятельно метода объекта (через prototype)

Где в Вашем коде самостоятельный метод объекта?
<div id="outer"></div>
<script>
function Person(name,surname,age) {
	this.name = name;
	this.surname = surname;
	this.age = age;
};
Person.prototype = {
	row: function() {
		return '<tr><td>' + this.name + '</td><td>' + this.surname + '</td><td>' + this.age + '</td></tr>'
	}
};

var str = '', str1, str2, str3, arr = [];
while (true) {
	if (!(str1 = prompt('Введите имя', 'Name'))) break;
	if (!(str2 = prompt('Введите фамилию', 'Surname'))) break;
	if (!(str3 = +prompt('Введите возраст', 0))) break;
	arr.push(new Person(str1, str2, str3));
};
for (var i = 0; i < arr.length; i++) str += arr[i].row();
document.getElementById('outer').innerHTML = '<table><tr><td>Имя</td><td>Фамилия</td><td>Возраст</td></tr>' + str + '</table>';
</script>

Anna77 13.10.2013 15:40

Благодарю за помощь!:)


Часовой пояс GMT +3, время: 22:13.