【发布时间】:2017-02-22 10:05:52
【问题描述】:
我正在访问在另一个 js 文件中编写的几个方法。所以我像这样访问它们:
文件 1:
function minit() {
this.addval = function(val1, val2) {
return val1 + val2;
}
function autoexecute(d) {
//do something here//
//raise event//
}
};
文件2:
var con = new minit();
var result = con.addval(2, 3);
/*
con.autoexecute(function(d) { //Wanna do something like this
alert(d);
});
*/
上面的事情按预期工作,得到结果..
现在,假设autoexecute(d) 方法在一段时间后自动调用。我怎么知道方法是否被执行?
所以,我想创建一个autoexecute(d)(在file1中)的事件(在file2中)。
更新: 我希望这个例子能帮助你理解这个问题..
company.js //这是主文件,将在 ui.html中用作参考
function hello(personname) { //this method will invoke automatically after 1 minute..
}
ui.html
<script src="company.js"></script>
<script>
$(document).ready(function() {
function bye(personame) { //this method will be called automatically if hello method invoked.... personame is the argument passed from hello method//
alert("comany.js -> hello function is executed");
}
});
</script>
【问题讨论】:
-
尽量让这个更清晰易懂。
-
请检查我已经更新了主线程..
-
我读过。如果它在 hello 方法所在的同一个文件中,bye 将被触发。但它们不在同一个文件中......这就是问题所在。 hello() 由comany.js 中的计时器自动触发..
-
在哪里声明 Bye 是完全不相关的,只要它在同一个 SCOPE 中,而不是在文件中。如果 Bye 是一个全局函数,它将触发,100%
标签: javascript jquery html d3.js