I have 2 js files. In the first one I have this:
var functionName = "video";
var cont = 1;
$(function() {
window.control = function control() {
var tipo1 = functionName + cont + "();";
var tipo2 = eval(tipo1);
tipo2;
cont++;
});
In the second one:
function video1() {
control();
}
function video2() {
control();
}
The first time was fine, but in the second, first execute video1()
and then video2()
, why?
Your definition is wrong:
window.control = function control() {
I imagine because of this it's firing control()
execution.
Change this to:
window.control = function() {
Also I see no reason for defining this function at DOM ready state. It will just cause confusion and potential reference issues. The definition of a function is only ran at execution point, these should potentially be on DOM ready state depending on their use.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.