【发布时间】:2021-05-28 14:13:29
【问题描述】:
如果这个问题不清楚,请告诉我,我会详细说明。不适合 JS。
我有一个 js 文件。我们称它为 jsFile1.js,其中我有两种方法。 Method1 正在从另一个文件 (anotherJsFile.js) 中调用,并且该调用将一个变量发送到 jsFile1.js 中的 Method1。
现在我想要我的第二个方法 Method2,它是从 jsFile1.js 内部调用的,它也能够使用从 anotherJsFile 发送到方法 1 的变量。
尝试使用 id 和设置值等,但它不起作用。有什么建议么?假设我必须将 const tmp 存储在 config 或 init 中,然后从 Method2 访问它?
File1
Method1(item, table) {
//item is a marked item from the table, table contains all entries
const tmp = {table, id: "tmpTable"};
}
Method2() {
const data = this.$$("tmpTable").getValues();
}
config() {
const Method2Button = {
view:"button",
label:"Method2",
click: () => this.Method2()
}}
【问题讨论】:
-
你创建一个简单的 store.js 文件,您可以在其中创建一个变量和获取和更新变量的 getter、setter 函数。那么您不必将其传递给
Method1。Method1和Method2都可以从 store.js 文件本身获取值。您只需要更新 store.js 中的值,一切都会正常 -
然而我想存储它初始化或配置的变量而不是另一个文件。
标签: javascript typescript variables frontend webix