English 中文(简体)
j 封闭范围链——如何看待受范围链约束的变量?
原标题:javascript closure scope chain- how to see the variables bound to the scope chain?
  • 时间:2011-11-14 21:37:18
  •  标签:
  • javascript

Javascript functions are objects and they have scope chain associated with them. If some closure exists with a function that has a different scope chain than the one that was in effect when they were defined.As an example invoking function is a returned function object from some other (parent) function that had a scope chain with a large number of private variables, so invoking function will use the already existing inherited scope chain of parent function as well as bounded old variables.

在不考虑上级职能的情况下,是否可检查与范围链有关的变量?

理想的情况是,必须跟踪父母职能中确定的变数,我的问题是没有考虑父母的职能,我们能否看到与范围链有关的变数?

如果是(任何方法?)我们能检查与范围链有关的变数的现值?

也可以给人提供范围链的结构(至少我知道它不像万国邮联那样的杂货,而是什么东西)。

最佳回答

在相同情况下创建的职能可使用范围变数(Java 文本在功能上范围)。

你可以与他们接触,但你可以采取报告他们的方法。 如果这是共同的要求,我建议把内部变量放在“组合”变量中:

var obj = (function (config) {
return {
  getTest: function () {
    return config.test;
  }
};
}({test: 1}));

Nick Zackas has done a good presentation about the scope chain (I think it s here: http://googlecode.blogspot.com/2009/06/nicholas-c-zakas-speed-up-your.html)

否则,使用 Chrome等开发工具的浏览器(Firebug常常忘记了范围变量是什么)。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签