i have functions in javascript need check function running is, indeed, correct function (ex, needs function something.stuff.morestuff.coolfunction
have called or wont run). i've tried getting function.caller
, returns function itself, , no way determine objects inside of.
given following setup:
function helloworld(){ if(/* exact path calling function */ === 'greetings.happy.classic.sayhello'){ console.log('hello world'); }else{ console.log(/* path earlier */ + ' not allowed.'); } } greetings = { happy: { classic: { sayhello: function(){ helloworld(); } saybye: function(){ helloworld(); } } }, angry: { sayhello: function(){ helloworld(); } }, simple: [ function(){ helloworld(); } ] } function saywords(){ helloworld(); }
what i'm trying accomplish this:
greetings.happy.classic.sayhello(); // => hello world! greetings.happy.classic.saybye(); // => greetings.happy.classic.saybye not allowed. greetings.angry.sayhello(); // => greetings.angry.sayhello not allowed. greetings.simple[0](); // => greetings.simple[0] not allowed. saywords(); // => saywords not allowed. helloworld(); // => null not allowed. // not sure come out of this, put null on 1
here's question in 1 neat little package:
how find exact object path (i.e.
greeting.happy.classic.sayhello
) of calling function?function.caller.name
returns name of function, not enough. need full tree of calling function's location.
this feels complex issue, thank help.
well, seem trying find out parent's reference in child object. not possible. check out post javascript object parent
Comments
Post a Comment