How to get the total number of objects created in javascript for a class? -


lets have following code snippet:

function airplane(id) {    this.id = id;   }  var air1 = new airplane(234); var air2 = new airplane(235); var air3 = new airplane(236); 

is there way total number of airplane objects created airplane.getcreatedlength()?

you keep track of in property attached constructor:

function airplane(id) {   this.id = id;   airplane.instances += 1; }  airplane.instances = 0;  var air1 = new airplane(234); var air2 = new airplane(235); var air3 = new airplane(236);  console.log(airplane.instances) // 3 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

php - How do you embed a video into a custom theme on WordPress? -