# 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 "class" (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. - 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 Here is a basic comparison:
| _object.js_ ```javascript var L = object.Constructor('L', Array, { constructor_attr: 'constructor', method: function(){ return 'constructor' }, }, { // prototype attribute (inherited)... attr: 'prototype', get prop(){ return 42 }, __init__: function(){ this.instance_attr = 7 }, }) ``` - Clear separation of constructor and `.prototype` data: - First block (optional) is merged with `L`, - Second block _is_ the `L.prototype`, - no direct way to do "private" definitions. | _ES6_ ```javascript class L extends Array { static constructor_attr = 'class' static method(){ return 'class' } // instance attribute (copied)... attr = 'instance' get prop(){ return 42 } constructor(){ super(...arguments) this.instance_attr = 7 } } ``` - pretty but misleading syntax, - `static` and instance definitions are not ordered, - `.attr` is copied to every instance |