从本地函数访问全局函数? [英] To access a Global Function from a Local Function ?

查看:141
本文介绍了从本地函数访问全局函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



好​​的查询可能看起来比较新手,但我仍然希望你能得到一些输入。

在JavaScript中是否可以从本地函数内部访问全局函数。



1>有可能...... ????

2>如果是的话,请指教...;);)



先谢谢了:):)

解决方案

< blockquote>当然有可能。但是,问题本身并非100%正确。



这就是:Javascript是一种解释性语言,功能是一等公民;它们也是物体。这意味着一切都是在执行期间,按执行顺序,包括函数在内的一切创建的。正如传统命令式语言所理解的那样,本地功能或全球功能的整体思想有些模糊。也许你的意思是在执行其他一些函数时创建的函数对象;这样的函数是局部的,并且从其他函数中看不到,除非它在某个参数中传递(作为函数对象,不与函数计算结果混淆)。在这种本地函数的范围内,可以访问外部范围的所有对象,包括函数。如果在执行内部函数的某些代码时创建了一些函数对象,则可以调用这样的外部作用域函数。



这里没什么值得启发的。只需调用它。



函数范围有很好的解释,例如: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope [ ^ ]。



-SA


Hi All,

Well query may seem rather Novice ,but still i would like some inputs at your end.
In JavaScript is it possible to access a Global Function from inside of a Local Function.

1> Is it possible...????
2> If yes, please enlighten... ;);)

Thanks in Advance :):)

解决方案

Of course it is possible. However, the question itself is not 100% correct.

Here is the thing: Javascript is an interpretive language, and functions are first-class citizens; they are also objects. It means that everything is created during execution, in the order of execution, everything, including the function. The whole idea of "local function" or "global function", as it is understood in the "traditional" imperative languages is somewhat blurred. Perhaps you mean the function object created during execution of some other function; such function is local and not visible from other functions, unless it is passed somewhere in some parameter (as function object, not to be mixed up with the result of calculation of function). Inside the scope of such "local" function, all object of outer scope are accessible, including function. If some function object is created at the moment of execution of some code of the inner function, such outer-scope function can be called.

There is nothing to enlighten here. Just call it.

The function scope is very well explained, for example, here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope[^].

—SA


这篇关于从本地函数访问全局函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆