# object.js _object.js_ provides a meta-constructor and a set of tools and utilities to aid in object/instance construction and implementing dynamic data and functionality inheritance within the established JavaScript prototypical object model and interfaces. This is an alternative to the ES6 `class` syntax in JavaScript and provides several advantages: - Simple way to define instance and constructor methods, properties and attributes, - Uniform and minimalistic definition syntax based on basic JavaScript object syntax, no special cases, special syntax or _"the same but slightly different"_ ways to do things, - _Transparently_ based on JavaScript's prototypical inheritance model, - Granular instance construction (a-la _Python's_ `.__new__(..)` and `.__init__(..)` methods), - Simple way to define callable instances (including a-la _Python's_ `.__call__(..)`), - Produces fully introspectable constructors/instances, i.e. no _direct_ way to define "private" attributes or methods, - Does not try to emulate constructs not present in the language (classes), - Less restrictive: - `new` is optional, - all input components are reusable, - no artificial restrictions. Disadvantages compared to the `class` syntax: - No _syntactic sugar_, - Slightly more complicated calling of `parent` (_super_) methods. Note that the produced constructors and objects are functionally identical (almost) to the ones produced via ES6 classes and are interchangeable with them. Here is a basic comparison:
| _object.js_ ```javascript var A = object.Constructor('A', { // prototype attribute (inherited)... attr: 'prototype', method: function(){ // ... }, }) var B = object.Constructor('B', A, { constructor_attr: 'constructor', constructor_method: function(){ return 'constructor' }, }, { get prop(){ return 42 }, __init__: function(){ this.instance_attr = 7 }, }) ``` - No _direct_ way to do "private" definitions, - Clear separation of constructor and `.prototype` For example, in `B`: - First block (optional) is merged with `B`, - Second block _is_ the `B.prototype`, - No special syntax, less distinct. | _ES6_ ```javascript class A { // instance attribute (copied)... attr = 'instance' method(){ // ... } } class B extends A { static constructor_attr = 'class' static constructor_method(){ return 'class' } get prop(){ return 42 } constructor(){ super(...arguments) this.instance_attr = 7 } } ``` - Syntax pretty but _misleading_; calling a constructor a class is not correct, - `static` and instance definitions are not ordered, - `.attr` is copied to every instance |