JavaScript - объекты
Кроме встроенных объектов, таких как:
- Number Object
- Boolean Object
- String Object
- Array Object
- Date Object
- Math Object
- RegExp Object
JavaScript позволяет создавать и использовать пользовательские объекты.
Терминология
- Пространство имен (Namespace)
Контейнер, который позволяет разработчикам объединять все функциональные возможности под уникальным, специфичных для приложения имя.
Определяет характеристики объекта. Класс представляет собой определение шаблона свойств и методов объекта.
Экземпляр класса.
Характеристика объекта, такая как цвет.
Функционал объекта, возможность производить действия с ним. Это подпрограммы или функции, связанные с классом.
- Конструктор (Constructor).
Метод, который вызывается в момент создания экземпляра объекта. Он, как правило, имеет то же имя, что и класс, который его содержит.
- Наследование (Inheritance).
Класс может наследовать свойства и методы из другого класса.
Объекты. Свойства. Методы.
Создание объекта.
Инициализатор объекта.
literal notation (initializer notation)
Прототип
Конструктор.
Constructor function
Задание, удаление, изменение свойств объекта.
Использование ключевого слова this.
Методы конструктора объектов*
- Object.assign()
- Copies the values of all enumerable own properties from one or more source objects to a target object.
- Object.create()
- Creates a new object with the specified prototype object and properties.
- Object.defineProperty()
- Adds the named property described by a given descriptor to an object.
- Object.defineProperties()
- Adds the named properties described by the given descriptors to an object.
- Object.entries()
- Returns an array of a given object's own enumerable property [key, value] pairs.
- Object.freeze()
- Freezes an object: other code can't delete or change any properties.
- Object.getOwnPropertyDescriptor()
- Returns a property descriptor for a named property on an object.
- Object.getOwnPropertyDescriptors()
- Returns an object containing all own property descriptors for an object.
- Object.getOwnPropertyNames()
- Returns an array containing the names of all of the given object's own enumerable and non-enumerable properties.
- Object.getOwnPropertySymbols()
- Returns an array of all symbol properties found directly upon a given object.
- Object.getPrototypeOf()
- Returns the prototype of the specified object.
- Object.is()
- Compares if two values are distinguishable (ie. the same)
- Object.isExtensible()
- Determines if extending of an object is allowed.
- Object.isFrozen()
- Determines if an object was frozen.
- Object.isSealed()
- Determines if an object is sealed.
- Object.keys()
- Returns an array containing the names of all of the given object's own enumerable properties.
- Object.preventExtensions()
- Prevents any extensions of an object.
- Object.seal()
- Prevents other code from deleting properties of an object.
- Object.setPrototypeOf()
- Sets the prototype (i.e., the internal [[Prototype]] property)
- Object.values()
- Returns an array of a given object's own enumerable values.
* По материалам сайта developer.mozilla.org