Can a JavaScript function know its own name, including object it is contained within -


I need JavaScript functions so that they can know about their names, in which something involves something like me The route does not seem like I. In all instances of SO, I do not fit much in terms of my use. Here's a fiddle to what I'm looking for:

  window.myMainNameSpace = {}; MyMainNameSpace.y = {z: Function (Funcocol) {var x = eval ("New" + Funcocol); I / * var myName = arguments.callee.toString (); MyName = myName.substr ('function' length); MyName = myName.substr (0, myName.indexOf ('(')); alarms (myName); console.log (arguments.callee); console.log (this.constructor); console.log (this.name); Console.log (this); console.log (this.constructor.toString ()); *}} myMainNameSpace.yz ('myMainNameSpace.ab ({arg1: 123})');  

I would like to be able to do a task that will return myMainNameSpace.ab or myMainNameSpace.ab () so that I can put it in some work Thank you!

You can do it without eval, you just iterate on each Must copy In each of the following, you have a new object in the last nested object:

  function callObjTail (obj) {var lastObj; var lastSign; for (var i = 'a' CharCodeAt (); true ; I ++) {console.log (i); if (obj [String.fromCharCode (i)]) {lastObj = obj; last sign = i; Obj = obj [string. FromCharCode (i)];} and { Break;}} if (last oz) {last oz [string.framecrod (final signal)] (); } And {obj [Object. Key (obje) [0]] (); }} Function buildObj (aimSign) {var obj = {}; Var head = ob; Var nests = ''; (Var i = 'a'.charCodeAt (); i & lt; aimSign.charCodeAt (); i ++) {obj [String.fromCharCode (i)] = {}; Obj = obj [string. FromCharCode (i)]; } Return {head: head, tail: obj}; } Var obj = buildObj ('E'); Console.log (obj.head); // {a: {b: {c: {d: {}}}} console.log (obj); Obj.tail.e = function () {console.log ('tail called');}; Console.log (obj.head.a.b.c.d.e ()); Console.log (obj.tail.e ()); // call tail obzell (obj.head) in the end call; CallObjTail (obj.tail);  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -