1

How can I get the name of an object as a string in javascript, particulary processing.js, but plain vanilla js is fine if that is what you know best. Take this object:

var obj = {
   w: 200,
   h: 300
};

and somehow make a function that returns its name:

var nameOfObj = function(obj){
   return *what should go here?*
};

so finally i can call this and get the name of my object, obj, as a string: "obj" help is much appreciated, thanks!

  • Not really possible in any elegant way. If you find yourself needing this, re-structure your code, perhaps have an object of objects, and use the key name as labels (eg `obj` here) – CertainPerformance Feb 22 '20 at 04:05
  • actually, that is what I have started.This is what it looks like so far:var object = function(x,y,w,h,imageName){ this.x = x; this.y = y; this.w = w; this.h = h; this.size = (w+h)/2; var img; for(var i = 0; i – Oyster_Bucket Feb 22 '20 at 04:08

0 Answers0