diff --git a/README.md b/README.md index 9df5bf9..6dce949 100755 --- a/README.md +++ b/README.md @@ -201,6 +201,7 @@ sources(, , ) -> ``` + Get parent attribute value or method ``` parent(, ) @@ -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(, ) + -> + -> undefined +``` + + Get parent method and call it ``` parentCall(, , ) @@ -236,6 +246,7 @@ mixin(, , ...) -> ``` + Mixin contents of objects into one ``` mixinFlat(, , ...) @@ -244,6 +255,7 @@ mixinFlat(, , ...) This is like `Object.assign(..)` but copies property objects rather than property values. + Make a raw (un-initialized) instance ``` makeRawInstance(, , ...) @@ -252,6 +264,7 @@ makeRawInstance(, , ...) _EXPERIMENTAL: a shorthand to this is defined as `Constructor.__rawinstance__(context, ..)`_ + Define an object constructor ``` Constructor(, ) @@ -259,6 +272,7 @@ Constructor(, , ) -> ``` + Shorthand to `Constructor(..)` ``` C(, ..) diff --git a/object.js b/object.js index ce6a2a6..92e2288 100755 --- a/object.js +++ b/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, ...) diff --git a/package.json b/package.json index ccf4f28..20b96ed 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-object", - "version": "2.5.1", + "version": "2.6.0", "description": "", "main": "object.js", "scripts": {