是否有可能无法从其他文件访问 ANSI C 中的函数?功能如何以及何时具有受限访问权限?起初我认为如果一个函数没有包含在任何标题中,它就是私有的。但似乎并非如此。
在我的 React 应用程序中,我从服务器获取自定义 javascript 文件并将其作为script标签附加到document.
这个新添加的自定义文件包含一个名为 的方法manipulator。现在,在其中一个组件中,我想调用该函数。据我所知,该函数应该存在于window全局对象中。
if(documnet.getElementById('customJsId')){ // check if the script tag exists in document
window.manipulator(); // which I get Property 'iframeManipulator' does not exist on type 'Window'.ts(2339)
}
Run Code Online (Sandbox Code Playgroud)
但这里我得到编译器错误
类型“Window”上不存在属性“manipulator”。ts(2339)
这是完全合乎逻辑的,但我没有找到一种方法来创建扩展接口window或任何其他方法来告诉编译器window调用中有一个可选函数manipulator。
任何帮助表示赞赏。
----------Just in case--how the script is added to document--------------
loadProjectCustomJS() {
runInAction(async () => {
thisfetchProjectJs().then((doc) => {
const body: HTMLBodyElement = document.getElementsByTagName('body')[0];
const customjs: HTMLScriptElement = document.createElement('script');
customjs.type = 'text/javascript'; …Run Code Online (Sandbox Code Playgroud) 这是一个场景。我想在 Aurelia 应用程序之外访问 Aurelia 功能。就像在运行我的应用程序时一样,如果我通过浏览器控制台调用方法“GetNotification(string Message)”,那么它应该被调用。
原因是我的 Aurelia 应用程序将在 .Net 应用程序浏览器中运行。所以我想在我的本机应用程序(.Net)和 Aurelia 应用程序之间进行通信。在 .Net 浏览器控件中,我们可以调用任何 Javascript 函数。但是我无法调用 Aurelia 函数,因为它没有对外公开。