added parentProperty(..)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-04-30 16:41:19 +03:00
parent 6d74f6a509
commit 92da56ed78
3 changed files with 43 additions and 3 deletions

View File

@ -201,6 +201,7 @@ sources(<object>, <name>, <callback>)
-> <list> -> <list>
``` ```
Get parent attribute value or method Get parent attribute value or method
``` ```
parent(<prototype>, <name>) parent(<prototype>, <name>)
@ -218,6 +219,15 @@ to the same method under the same name, `parent(..)` can't distinguish
between these references and will always return the second one._ between these references and will always return the second one._
Get parent property descriptor
```
parentProperty(<prototype>, <name>)
-> <prop-descriptor>
-> undefined
```
Get parent method and call it Get parent method and call it
``` ```
parentCall(<prototype>, <name>, <this>) parentCall(<prototype>, <name>, <this>)
@ -236,6 +246,7 @@ mixin(<root>, <object>, ...)
-> <object> -> <object>
``` ```
Mixin contents of objects into one Mixin contents of objects into one
``` ```
mixinFlat(<root>, <object>, ...) mixinFlat(<root>, <object>, ...)
@ -244,6 +255,7 @@ mixinFlat(<root>, <object>, ...)
This is like `Object.assign(..)` but copies property objects rather than This is like `Object.assign(..)` but copies property objects rather than
property values. property values.
Make a raw (un-initialized) instance Make a raw (un-initialized) instance
``` ```
makeRawInstance(<context>, <constructor>, ...) makeRawInstance(<context>, <constructor>, ...)
@ -252,6 +264,7 @@ makeRawInstance(<context>, <constructor>, ...)
_EXPERIMENTAL: a shorthand to this is defined as `Constructor.__rawinstance__(context, ..)`_ _EXPERIMENTAL: a shorthand to this is defined as `Constructor.__rawinstance__(context, ..)`_
Define an object constructor Define an object constructor
``` ```
Constructor(<name>, <prototype>) Constructor(<name>, <prototype>)
@ -259,6 +272,7 @@ Constructor(<name>, <class-prototype>, <prototype>)
-> <constructor> -> <constructor>
``` ```
Shorthand to `Constructor(..)` Shorthand to `Constructor(..)`
``` ```
C(<name>, ..) C(<name>, ..)

View File

@ -66,6 +66,8 @@ function(text, tab_size){
// -> list // -> list
// //
// //
// NOTE: this will not trigger any props...
//
// XXX should the callback(..) be used to break (current) or filter/map??? // XXX should the callback(..) be used to break (current) or filter/map???
// XXX revise name... // XXX revise name...
var sources = var sources =
@ -131,8 +133,10 @@ function(obj, name, callback){
// loops, for example, this.method deep in a chain will resolve to // loops, for example, this.method deep in a chain will resolve to
// the first .method value visible from 'this', i.e. the top most // the first .method value visible from 'this', i.e. the top most
// value and not the value visible from that particular level... // value and not the value visible from that particular level...
// // NOTE: in the general case this will get the value of the returned
// XXX need to add a way to work with props... (???) // property/attribute, the rest of the way passive to props.
// The method case will get the value of every method from 'this'
// and to the method after the match.
var parent = var parent =
module.parent = module.parent =
function(proto, name){ function(proto, name){
@ -154,6 +158,28 @@ function(proto, name){
: undefined } : undefined }
// Find the next parent property descriptor in the prototype chain...
//
// parentProperty(proto, name)
// -> prop-descriptor
//
//
// This is like parent(..) but will get a property descriptor...
//
var parentProperty =
module.parentProperty =
function(proto, name){
// get second source...
var c = 0
var res = sources(proto, name,
function(obj){ return c++ == 1 })
.pop()
return res ?
// get next value...
Object.getOwnPropertyDescriptor(res, name)
: undefined }
// Find the next parent method and call it... // Find the next parent method and call it...
// //
// parentCall(proto, name, this, ...) // parentCall(proto, name, this, ...)

View File

@ -1,6 +1,6 @@
{ {
"name": "ig-object", "name": "ig-object",
"version": "2.5.1", "version": "2.6.0",
"description": "", "description": "",
"main": "object.js", "main": "object.js",
"scripts": { "scripts": {