Math.random() javascript function *undefined* on Chrome

前端 未结 4 1664
忘掉有多难
忘掉有多难 2020-12-21 14:09

In first place, I am convinced that this is a trivial question, but I cannot understand why this is happening and I couldn\'t find an answer anywhere else. I googled my issu

相关标签:
4条回答
  • 2020-12-21 14:56

    I found another situation that could cause this to happen. I was converting a PHP function to a JS function and I had the following line:

    ticks += "," . Math.floor(yyy * intMax);
    

    Changing it to

    ticks += "," + Math.floor(yyy * intMax);
    

    solved the problem

    0 讨论(0)
  • 2020-12-21 15:04

    Another library on your page is overriding the Math object. This is one of the reasons that polluting the Global Namespace is frowned upon.

    For reference Math should return the following

    enter image description here

    0 讨论(0)
  • 2020-12-21 15:10

    Somehow, NotScript got automatically installed in my Chrome browser on Ubuntu 16.04. That inserts the script you show in your update just after the <html> tag.

    I had to go to the settings, look at the extensions, disable the NotScripts and then restart Chrome to it would be gone.

    On Ubuntu, this must be very recent or the script got updated recently because I ran the exact same test in Chrome, with the exact same scripts, a few days ago, and it was working just fine.

    Interestingly enough, it looks like it was removed 2 years ago (Nov 2014) and maybe re-added recently?

    0 讨论(0)
  • 2020-12-21 15:12

    Something overrides Math in your code.

    Execute Math in your chrome console. Execute context menu on it and select "Show function definition". This will probably lead you to "Sources" panel and show script where it is being overriden.

    EDIT: this is chrome extension called notscripts. Disable it. Here is the source code for proof: webarchive

    0 讨论(0)
提交回复
热议问题