mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 18:40:08 +00:00
added parentProperty(..)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
6d74f6a509
commit
92da56ed78
14
README.md
14
README.md
@ -201,6 +201,7 @@ sources(<object>, <name>, <callback>)
|
||||
-> <list>
|
||||
```
|
||||
|
||||
|
||||
Get parent attribute value or method
|
||||
```
|
||||
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._
|
||||
|
||||
|
||||
Get parent property descriptor
|
||||
|
||||
```
|
||||
parentProperty(<prototype>, <name>)
|
||||
-> <prop-descriptor>
|
||||
-> undefined
|
||||
```
|
||||
|
||||
|
||||
Get parent method and call it
|
||||
```
|
||||
parentCall(<prototype>, <name>, <this>)
|
||||
@ -236,6 +246,7 @@ mixin(<root>, <object>, ...)
|
||||
-> <object>
|
||||
```
|
||||
|
||||
|
||||
Mixin contents of objects into one
|
||||
```
|
||||
mixinFlat(<root>, <object>, ...)
|
||||
@ -244,6 +255,7 @@ mixinFlat(<root>, <object>, ...)
|
||||
This is like `Object.assign(..)` but copies property objects rather than
|
||||
property values.
|
||||
|
||||
|
||||
Make a raw (un-initialized) instance
|
||||
```
|
||||
makeRawInstance(<context>, <constructor>, ...)
|
||||
@ -252,6 +264,7 @@ makeRawInstance(<context>, <constructor>, ...)
|
||||
|
||||
_EXPERIMENTAL: a shorthand to this is defined as `Constructor.__rawinstance__(context, ..)`_
|
||||
|
||||
|
||||
Define an object constructor
|
||||
```
|
||||
Constructor(<name>, <prototype>)
|
||||
@ -259,6 +272,7 @@ Constructor(<name>, <class-prototype>, <prototype>)
|
||||
-> <constructor>
|
||||
```
|
||||
|
||||
|
||||
Shorthand to `Constructor(..)`
|
||||
```
|
||||
C(<name>, ..)
|
||||
|
||||
30
object.js
30
object.js
@ -66,6 +66,8 @@ function(text, tab_size){
|
||||
// -> list
|
||||
//
|
||||
//
|
||||
// NOTE: this will not trigger any props...
|
||||
//
|
||||
// XXX should the callback(..) be used to break (current) or filter/map???
|
||||
// XXX revise name...
|
||||
var sources =
|
||||
@ -131,8 +133,10 @@ function(obj, name, callback){
|
||||
// loops, for example, this.method deep in a chain will resolve to
|
||||
// the first .method value visible from 'this', i.e. the top most
|
||||
// value and not the value visible from that particular level...
|
||||
//
|
||||
// XXX need to add a way to work with props... (???)
|
||||
// NOTE: in the general case this will get the value of the returned
|
||||
// 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 =
|
||||
module.parent =
|
||||
function(proto, name){
|
||||
@ -154,6 +158,28 @@ function(proto, name){
|
||||
: 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...
|
||||
//
|
||||
// parentCall(proto, name, this, ...)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-object",
|
||||
"version": "2.5.1",
|
||||
"version": "2.6.0",
|
||||
"description": "",
|
||||
"main": "object.js",
|
||||
"scripts": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user