# Get instance name in a class

**URL:** <https://forum.kirupa.com/t/get-instance-name-in-a-class/259853>\
**Category:** Uncategorized\
**Created:** [May 9, 2008, 12:46pm UTC](https://forum.kirupa.com/t/get-instance-name-in-a-class/259853 "2008-05-09T12:46:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![amod](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@amod](https://forum.kirupa.com/u/amod)\
**Post date:** [May 9, 2008, 12:46pm UTC](https://forum.kirupa.com/t/get-instance-name-in-a-class/259853/1 "2008-05-09T12:46:43Z")

</div>

Hello!  
I have searched around a while, but couldn’t find what i’m looking for.

I have created a class: Persons  
when I make an instance of this class I want to get the name of this instance and save it as a static var (Array). I want to do this so that i later can call a static function to all instances.

Like this:  
var noen: Persons=new Persons(“John”);  
var neon: Persons=new Persons(“Mike”);  
var neonnoe: Persons=new Persons(“Karl”);  
Persons.jumpAll();

And then everybody jumps. (No mater what I called the instances.)

Does anybody know how to do this?  
Thanks for your attention.

Mr Amod

---

<div class="post-metadata">

**Author:** ![Valaran](https://avatars.discourse-cdn.com/v4/letter/v/ee59a6/32.png) [@Valaran](https://forum.kirupa.com/u/Valaran)\
**Post date:** [May 9, 2008, 5:17pm UTC](https://forum.kirupa.com/t/get-instance-name-in-a-class/259853/2 "2008-05-09T17:17:01Z")

</div>

I’m not to much up to date on OOP, but couldnt you like… MAke 2 classes instead? Where one is the class for the actual ‘person’ and the other class is… Lets say, the parent class, ‘persons’?

I mean, like when you create a ‘person’ you could populate a array in the class ‘persons’ which would have a function called persons.jumpAll(); which would execute it for all the ‘person’ which has been pushed into its array?
