Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object (string or array) NAME. how to get it?

I need a prototype done in this way:

Array.prototype.getname=function(){ [...]return arrayname; }

So I can:

z=new Array;
alert(z.name);

and I should have "z" in the alert.

I'm working on Chrome and caller/callee seem to return empty.

like image 592
Zibri Avatar asked Nov 19 '25 09:11

Zibri


2 Answers

The best you can do is to always explicitly set the array's name when you create it:

var z = [];
z.name = 'z';

You could do this by having a function makeArray that sets the name passed as an argument:

function makeArray(name) {
    var arr = [];
    arr.name = name;
    return arr;
}

The essential problem is that the several variables can point to the same array:

var z = [],
    x = z;

Then what should the name be: z or x?

like image 164
Rich Avatar answered Nov 22 '25 00:11

Rich


The problem is that a variable (like an array) can have several names. For example:

var a = new Array();
var b = a;
a[0] = "hello";
alert(b[0]);//"hello"

What is the name of the array, a or b?

like image 37
Marius Avatar answered Nov 22 '25 00:11

Marius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!