mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 18:40:08 +00:00
cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
5f85e29f3e
commit
aee689646b
14
README.md
14
README.md
@ -135,7 +135,7 @@ class B extends A {
|
|||||||
- [`hasMixin(..)`](#hasmixin)
|
- [`hasMixin(..)`](#hasmixin)
|
||||||
- [`mixout(..)`](#mixout)
|
- [`mixout(..)`](#mixout)
|
||||||
- [`mixinFlat(..)`](#mixinflat)
|
- [`mixinFlat(..)`](#mixinflat)
|
||||||
- [`makeRawInstance(..)`](#makerawinstance)
|
- [`RawInstance(..)`](#rawinstance)
|
||||||
- [`Constructor(..)` / `C(..)`](#constructor--c)
|
- [`Constructor(..)` / `C(..)`](#constructor--c)
|
||||||
- [Utilities](#utilities)
|
- [Utilities](#utilities)
|
||||||
- [`normalizeIndent(..)` / `normalizeTextIndent(..)`](#normalizeindent--normalizetextindent)
|
- [`normalizeIndent(..)` / `normalizeTextIndent(..)`](#normalizeindent--normalizetextindent)
|
||||||
@ -450,7 +450,7 @@ JavaScript object.
|
|||||||
For example, this will happily create a normal native array object
|
For example, this will happily create a normal native array object
|
||||||
`['a', 'b', 'c']`:
|
`['a', 'b', 'c']`:
|
||||||
```javascript
|
```javascript
|
||||||
var l = object.makeRawInstance(null, Array, 'a', 'b', 'c')
|
var l = object.RawInstance(null, Array, 'a', 'b', 'c')
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@ -586,15 +586,15 @@ This is like `Object.assign(..)` but copies property descriptors rather
|
|||||||
than property values.
|
than property values.
|
||||||
|
|
||||||
|
|
||||||
### `makeRawInstance(..)`
|
### `RawInstance(..)`
|
||||||
|
|
||||||
Make a raw (un-initialized) instance
|
Make a raw (un-initialized) instance
|
||||||
```
|
```
|
||||||
makeRawInstance(<context>, <constructor>, ..)
|
RawInstance(<context>, <constructor>, ..)
|
||||||
-> <object>
|
-> <object>
|
||||||
```
|
```
|
||||||
|
|
||||||
`makeRawInstance(..)` will do the following:
|
`RawInstance(..)` will do the following:
|
||||||
- Create an instance object
|
- Create an instance object
|
||||||
- get result of `.__new__(..)` if defined, or
|
- get result of `.__new__(..)` if defined, or
|
||||||
- if prototype is a function or `.__call__(..)` is defined, create a
|
- if prototype is a function or `.__call__(..)` is defined, create a
|
||||||
@ -622,12 +622,12 @@ Constructor(<name>, <constructor-mixin>, <prototype>)
|
|||||||
`Constructor(..)` essentially does the following:
|
`Constructor(..)` essentially does the following:
|
||||||
- Creates a _constructor_ function,
|
- Creates a _constructor_ function,
|
||||||
- Sets constructor `.name` and `.toString(..)` for introspection,
|
- Sets constructor `.name` and `.toString(..)` for introspection,
|
||||||
- Creates `.__rawinstance__(..)` wrapper to `makeRawInstance(..)`
|
- Creates `.__rawinstance__(..)` wrapper to `RawInstance(..)`
|
||||||
- Sets constructor `.__proto__`, `.prototype` and `.prototype.constructor`,
|
- Sets constructor `.__proto__`, `.prototype` and `.prototype.constructor`,
|
||||||
- Mixes in _constructor-mixin_ if given.
|
- Mixes in _constructor-mixin_ if given.
|
||||||
|
|
||||||
The resulting _constructor_ function when called will:
|
The resulting _constructor_ function when called will:
|
||||||
- call constructor's `.__rawinstance__(..)` if defined or `makeRawInstance(..)`
|
- call constructor's `.__rawinstance__(..)` if defined or `RawInstance(..)`
|
||||||
to create an instance,
|
to create an instance,
|
||||||
- call instance's `.__init__(..)` if present.
|
- call instance's `.__init__(..)` if present.
|
||||||
|
|
||||||
|
|||||||
21
object.js
21
object.js
@ -447,7 +447,7 @@ function(base, ...objects){
|
|||||||
|
|
||||||
// Make an uninitialized instance object...
|
// Make an uninitialized instance object...
|
||||||
//
|
//
|
||||||
// makeRawInstance(context, constructor, ...)
|
// RawInstance(context, constructor, ...)
|
||||||
// -> instance
|
// -> instance
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@ -473,7 +473,7 @@ function(base, ...objects){
|
|||||||
// can be used to construct any object...
|
// can be used to construct any object...
|
||||||
// Example:
|
// Example:
|
||||||
// // new is optional...
|
// // new is optional...
|
||||||
// var l = new makeRawInstance(null, Array, 'a', 'b', 'c')
|
// var l = new RawInstance(null, Array, 'a', 'b', 'c')
|
||||||
// NOTE: the following are not the same in structure but functionally
|
// NOTE: the following are not the same in structure but functionally
|
||||||
// are identical:
|
// are identical:
|
||||||
// var C = Constructor('C', function(){ .. })
|
// var C = Constructor('C', function(){ .. })
|
||||||
@ -482,8 +482,9 @@ function(base, ...objects){
|
|||||||
// the difference is in C.prototype vs. C2.prototype, the first
|
// the difference is in C.prototype vs. C2.prototype, the first
|
||||||
// being a function while the second is an object with a call
|
// being a function while the second is an object with a call
|
||||||
// method...
|
// method...
|
||||||
var makeRawInstance =
|
// NOTE: essentially this is an extended version of Reflect.construct(..)
|
||||||
module.makeRawInstance =
|
var RawInstance =
|
||||||
|
module.RawInstance =
|
||||||
function(context, constructor, ...args){
|
function(context, constructor, ...args){
|
||||||
var _mirror_doc = function(func, target){
|
var _mirror_doc = function(func, target){
|
||||||
Object.defineProperty(func, 'toString', {
|
Object.defineProperty(func, 'toString', {
|
||||||
@ -563,7 +564,7 @@ function(context, constructor, ...args){
|
|||||||
//
|
//
|
||||||
// Create raw/uninitialized instance...
|
// Create raw/uninitialized instance...
|
||||||
// constructor.__rawinstance__(..)
|
// constructor.__rawinstance__(..)
|
||||||
// makeRawInstance(null, constructor, ..)
|
// RawInstance(null, constructor, ..)
|
||||||
// -> raw-instance
|
// -> raw-instance
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@ -575,7 +576,7 @@ function(context, constructor, ...args){
|
|||||||
//
|
//
|
||||||
// Create and initialization protocol:
|
// Create and initialization protocol:
|
||||||
// 1) raw instance is created:
|
// 1) raw instance is created:
|
||||||
// a) constructor.__rawinstance__(..) / makeRawInstance(..) called:
|
// a) constructor.__rawinstance__(..) / RawInstance(..) called:
|
||||||
// - call .__new__(..) if defined and get return value as
|
// - call .__new__(..) if defined and get return value as
|
||||||
// instance, or
|
// instance, or
|
||||||
// - if .__call__(..) defined or prototype is a function, wrap
|
// - if .__call__(..) defined or prototype is a function, wrap
|
||||||
@ -607,7 +608,7 @@ function(context, constructor, ...args){
|
|||||||
// Handle uninitialized instance construction
|
// Handle uninitialized instance construction
|
||||||
// .__rawinstance__(context, ...)
|
// .__rawinstance__(context, ...)
|
||||||
// -> instance
|
// -> instance
|
||||||
// NOTE: This is a shorthand to makeRawInstance(..) see it for
|
// NOTE: This is a shorthand to RawInstance(..) see it for
|
||||||
// details.
|
// details.
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@ -626,7 +627,7 @@ function(context, constructor, ...args){
|
|||||||
// -> ..
|
// -> ..
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// NOTE: raw instance creation is defined by makeRawInstance(..) so see
|
// NOTE: raw instance creation is defined by RawInstance(..) so see
|
||||||
// it for more info.
|
// it for more info.
|
||||||
// NOTE: raw instance creation can be completely overloaded by defining
|
// NOTE: raw instance creation can be completely overloaded by defining
|
||||||
// .__rawinstance__(..) on the constructor.
|
// .__rawinstance__(..) on the constructor.
|
||||||
@ -720,7 +721,7 @@ function Constructor(name, a, b, c){
|
|||||||
// create raw instance...
|
// create raw instance...
|
||||||
var obj = _constructor.__rawinstance__ ?
|
var obj = _constructor.__rawinstance__ ?
|
||||||
_constructor.__rawinstance__(this, ...arguments)
|
_constructor.__rawinstance__(this, ...arguments)
|
||||||
: makeRawInstance(this, _constructor, ...arguments)
|
: RawInstance(this, _constructor, ...arguments)
|
||||||
// initialize...
|
// initialize...
|
||||||
obj.__init__ instanceof Function
|
obj.__init__ instanceof Function
|
||||||
&& obj.__init__(...arguments)
|
&& obj.__init__(...arguments)
|
||||||
@ -760,7 +761,7 @@ function Constructor(name, a, b, c){
|
|||||||
_constructor.__rawinstance__ instanceof Function
|
_constructor.__rawinstance__ instanceof Function
|
||||||
|| (_constructor.__rawinstance__ =
|
|| (_constructor.__rawinstance__ =
|
||||||
function(context, ...args){
|
function(context, ...args){
|
||||||
return makeRawInstance(context, this, ...args) })
|
return RawInstance(context, this, ...args) })
|
||||||
!!constructor_proto
|
!!constructor_proto
|
||||||
&& (_constructor.__proto__ = constructor_proto)
|
&& (_constructor.__proto__ = constructor_proto)
|
||||||
_constructor.prototype = proto
|
_constructor.prototype = proto
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-object",
|
"name": "ig-object",
|
||||||
"version": "3.3.2",
|
"version": "4.0.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "object.js",
|
"main": "object.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user