Я объявляю пользователя класса, а затем добавляю объект класса
function user(uid, pwd){
this.uid = uid
this.pwd = pwd
function displayAll(){
document.write(uid)
document.write(pwd)
}
}
var Aaron = new user("Aaron", "123")
document.write(Aaron.uid)
Я хочу просмотреть свойства, распечатав их по одному, я пробовал это
Aaron.displayAll()
который ничего не оценивает, я что-то упустил? Любая помощь будет потрясающей :)
Функция объявлена в функции user, но никогда не привязана к ней, поэтому она не отображается и недоступна, в результате чего функция доступна только внутри функции user.



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Вы можете изменить с function displayAll() на this.displayAll = function displayAll()
function user(uid, pwd)
{
this.uid = uid
this.pwd = pwd
this.displayAll = function displayAll()
{
document.write(uid)
document.write(pwd)
}
}
var Aaron = new user("Aaron", "123")
document.write(Aaron.uid)
Aaron.displayAll();Вот для чего нужна цепочка прототипов.
function User(uid, pwd) {
this.uid = uid
this.pwd = pwd
}
User.prototype.displayAll = function() {
document.write(this.uid)
document.write(this.pwd)
}
var aaron = new User("Aaron", "123");
aaron.displayAll();Другой способ — использовать синтаксис Сорт.
class User {
constructor(uid, pwd) {
this.uid = uid;
this.pwd = pwd;
}
displayAll(){
document.write(this.uid);
document.write(this.pwd);
}
}
var Aaron = new User("Aaron", "123");
Aaron.displayAll();
Вам нужно вернуть это в конце функции