1

Is there a convenient way to get a list of all objects whose prototype is the given object? I'm inspecting slotNames on Object in an attempt to find a method that might do this, but I'm coming up short. It appears one could scan Lobby, but I thought I'd make sure I wasn't missing something more immediate.

StevenC
  • 1,172
  • 1
  • 9
  • 17
  • What objects do you want to filter for it, all of your program? That appears hardly useful. – Bergi Jan 18 '14 at 16:03
  • 1
    What do you need this for? May you want to overwrite `init` with something that adds new instances to a static list at your cloned object. – Bergi Jan 18 '14 at 16:04
  • It's more a learning question. I can crawl the chain of prototypes, but the introspection doesn't seem to go the other way immediately. So no, there's no real-world problem to solve. – StevenC Jan 18 '14 at 16:04
  • On the other hand, if you wanted to implement an environment like SmallTalk has, then this list would be useful for browsing objects. – StevenC Jan 18 '14 at 16:06

1 Answers1

3

Naively, you could iterate Collector allObjects and apply a select over that. However, keep in mind that this will linearly scan all objects in the known heap, so it could take some time depending on your heap size.

Collector allObjects select(proto == Foo)
# list(Foo_0x7f81b2946c30)
jer
  • 20,094
  • 5
  • 45
  • 69