开发者

arguments.callee.caller... how to get 'this' reference of a caller object?

开发者 https://www.devze.com 2023-04-03 11:23 出处:网络
I have a configuration object which may c开发者_运维百科ontainer scope property and may not and I pass it to my function. This function creates some callback functions and applies \'scope\' property t

I have a configuration object which may c开发者_运维百科ontainer scope property and may not and I pass it to my function. This function creates some callback functions and applies 'scope' property to them. I want to force this function to provide the scope even if it is not actually specified - to get 'this' reference of a caller, something like this:

function someFunc (config)
{
  var scope = config.scope ? config.scope : arguments.callee.caller... (?);
  config.preAction.apply(scope);
}

Is it actually possible?


Just as you assumed in your comment, the answer is that it is impossible. JavaScript is simply not introspective enough.

0

精彩评论

暂无评论...
验证码 换一张
取 消