mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 18:40:08 +00:00
experimenting with generators...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
a30c562660
commit
637c53d238
42
object.js
42
object.js
@ -422,6 +422,7 @@ BOOTSTRAP(function(){
|
|||||||
// STOP(value) yielded / thrown
|
// STOP(value) yielded / thrown
|
||||||
// -> value yielded and iteration stops
|
// -> value yielded and iteration stops
|
||||||
//
|
//
|
||||||
|
// XXX doc!!!
|
||||||
// XXX should we use this for sources(..) and friends...
|
// XXX should we use this for sources(..) and friends...
|
||||||
var stoppable =
|
var stoppable =
|
||||||
module.stoppable =
|
module.stoppable =
|
||||||
@ -490,6 +491,43 @@ function(func){
|
|||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// Prototype chain content access...
|
// Prototype chain content access...
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
var _sources =
|
||||||
|
module._sources =
|
||||||
|
function*(obj, name){
|
||||||
|
while(obj != null){
|
||||||
|
if(name === undefined
|
||||||
|
|| obj.hasOwnProperty(name)
|
||||||
|
|| (name == '__call__'
|
||||||
|
&& typeof(obj) == 'function')){
|
||||||
|
yield obj }
|
||||||
|
obj = obj.__proto__ } }
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
var _entries =
|
||||||
|
module._entries =
|
||||||
|
function*(obj, name, props=false){
|
||||||
|
for(var o of _sources(obj, name)){
|
||||||
|
yield [
|
||||||
|
obj,
|
||||||
|
props ?
|
||||||
|
Object.getOwnPropertyDescriptor(obj, name)
|
||||||
|
// handle callable instance...
|
||||||
|
: !(name in obj)
|
||||||
|
&& name == '__call__'
|
||||||
|
&& typeof(obj) == 'function' ?
|
||||||
|
obj
|
||||||
|
: obj[name]
|
||||||
|
] }}
|
||||||
|
|
||||||
|
// XXX
|
||||||
|
var _values =
|
||||||
|
module._values =
|
||||||
|
function*(obj, name, props=false){
|
||||||
|
for(var [_, value] of _entries(...arguments)){
|
||||||
|
yield value }}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Get a list of source objects for a prop/attr name...
|
// Get a list of source objects for a prop/attr name...
|
||||||
//
|
//
|
||||||
@ -545,8 +583,7 @@ function(obj, name, callback){
|
|||||||
// get full chain...
|
// get full chain...
|
||||||
if(typeof(name) == 'function'){
|
if(typeof(name) == 'function'){
|
||||||
callback = name
|
callback = name
|
||||||
name = undefined
|
name = undefined }
|
||||||
}
|
|
||||||
var i = 0
|
var i = 0
|
||||||
var o
|
var o
|
||||||
var res = []
|
var res = []
|
||||||
@ -573,6 +610,7 @@ function(obj, name, callback){
|
|||||||
return res.flat() }
|
return res.flat() }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Get a list of values/props set in source objects for a prop/attr name...
|
// Get a list of values/props set in source objects for a prop/attr name...
|
||||||
//
|
//
|
||||||
// Get values...
|
// Get values...
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user