简体   繁体   English

如何从另一个范围访问此功能?

[英]How do I access this function from within another scope?

I am trying to develop a sdk for a client and the client should setar its data before loading the file with javascrip. 我正在尝试为客户端开发一个sdk,并且客户端应先设置其数据,然后再使用javascrip加载文件。 The function is in global scope and my script is in another scope. 该函数在全局范围内,而我的脚本在另一个范围内。 How do I access customer data from another scope? 如何从另一个范围访问客户数据?

Global function 全局功能

  window.codeInit = function () { var init = { ID: "1234", elementStart: "#contentDiv" } }; 

Scope of where I want to access the function data 我要访问功能数据的范围

 (function(window){ //Access from here })(window) 

Like this 像这样

var init = {
    ID: "1234",
    elementStart: "#contentDiv"
}
window.codeInit = function() {
    console.log(init.ID);
};

(function(window){
    codeInit();
})(window)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从函数范围之外访问数据? - How do I access data from outside a function's scope? 当我需要的数据在全局 scope 中时,如何在另一个 function 中调用 function? - How do I call a function within another function when the data I need is in the global scope? 如何从另一个元素访问一个元素? - How Do I Access An Element from Within Another Element? 如何在函数范围内将div附加到具有特定ID的另一个div - How do I append a div to another div with a specific id within the scope of a function 如何通过范围从另一个控制器内部访问一个控制器的功能? - How to access functions of a controller from within another controller via scope? 如何从setTimeout中获取另一个作用域中的变量集? - How do I get a variable set in another scope from within a setTimeout? 如何在另一个Jquery文件的作用域内访问JQuery函数? - How do access a JQuery function inside a scope in another Jquery file? 如何从一个函数访问变量到另一个函数 - How do I access the variable from one function to another 访问不在范围内的功能 - Access a Function not within the Scope 如何访问自身内的对象,另一个对象内的对象? - How do I access an object within itself, within another object?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM