1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-26 20:28:49 +08:00

add KeysByParent function for recursively getting object keys

This commit is contained in:
deoxxa
2016-04-27 16:08:07 +10:00
parent b283580aea
commit 6e7c8df250
2 changed files with 35 additions and 0 deletions

19
otto.go
View File

@@ -655,6 +655,25 @@ func (self Object) Keys() []string {
return keys
}
// Get the keys (and those of the parents) for the object, in order of
// "closest" to "furthest"
func (self Object) KeysByParent() [][]string {
var a [][]string
for o := self.object; o != nil; o = o.prototype {
var l []string
o.enumerate(false, func(name string) bool {
l = append(l, name)
return true
})
a = append(a, l)
}
return a
}
// Class will return the class string of the object.
//
// The return value will (generally) be one of: