简体   繁体   English

字符串和函数的同名

[英]Same name for a string and a function

Right now I'm having a major brain fart.现在我有一个严重的脑放屁。 I have this function:我有这个功能:

function uplodeVirus(){
  console.log('working')
  console.log('uplodeVirus')
  var form = document.getElementsByTagName('form')[1]
  console.log(form)
  var select = form.children[0]
  console.log(select)
  for (x in select) {
    var lN = select[x].innerHTML // var linkName
    if (lN == "vspam 0.3 [OpenRelay-backdoor.vspam ] (0.003 Gb)"){
      value = select[x].value
      select[x].setAttribute("selected", "selected");
      form.submit()
      break
    }  
  }
}

Don't worry its not a real Virus!!!别担心它不是真正的病毒!!! This is a bot for a game called slave hack - for learning purposes这是一个名为 slave hack 的游戏的机器人 - 用于学习目的

Anyways, when I call the function:无论如何,当我调用函数时:

var ip = '2.2.2.2'
var uplodeVirus = 'http://www.slavehack.com/index2.php?page=internet&var2=' + ip + '&var3=files&aktie=upload'
var currentUrl = window.location.href
console.log(currentUrl)
console.log(uplodeVirus)
if (currentUrl == uplodeVirus) { //Yes, I made sure that currentUrl = uplodeVirus
  uplodeVirus()
}

Nothing happens... but if I take the code out of the function and do this:什么也没发生……但是如果我从函数中取出代码并执行以下操作:

if (currentUrl == uplodeVirus){ 
  console.log('working')
  console.log('uplodeVirus')
  var form = document.getElementsByTagName('form')[1]
  console.log(form)
  var select = form.children[0]
  console.log(select)
  for (x in select) {
    var lN = select[x].innerHTML // var linkName
    if (lN == "vspam 0.3 [OpenRelay-backdoor.vspam ] (0.003 Gb)"){
      value = select[x].value
      select[x].setAttribute("selected", "selected");
      form.submit()
      break
    }  
  }
}

It works!!!有用!!! Now, I could go with option B, but I really want to figure out what i did wrong.现在,我可以选择选项 B,但我真的很想弄清楚我做错了什么。

Thanks in advance!提前致谢!

You are naming both a URL variable and a function with the same name: uplodeVirus您正在命名一个 URL 变量和一个具有相同名称的函数: uplodeVirus

Since the variable is initialized to hold a string before you try to call the function, calling uplodeVirus() is the same as calling ("")() .由于在您尝试调用函数之前变量已初始化为保存字符串,因此调用uplodeVirus()与调用("")() It doesn't make any sense, because a string is not a function.这没有任何意义,因为字符串不是函数。

Try changing the name of one or the other.尝试更改其中一个的名称。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM