Using Function on Date says is not a function

  var stampDate = Date.now();
  var localDate = new Date (stampDate);
  var newlocalDate = (stampDate + 4 * 24 * 60 * 60 * 1000);


  var downloadtime = myCipher(newlocalDate);
TypeError: text.split is not a function
    at worker.js:9:25
    at handleRequest (worker.js:64:30)

There are quite a few things off here.

  • await can’t be used in this context
  • The error message refers to split, but the code you posted does not reference that

Generally speaking, code questions are off-topic for the forum and better discussed at StackOverflow or Reddit.

I understand that. But forget await. i removed it.

The funcation i am using is private crypt. But it works if i use it on anything else.

eg. myCipher(“Anything Here”); works fine.

But its not working on date,

I am asking why’s that. Somehow it doesn’t read the date and picks up something else which messes with the function.

Post a link to https://cloudflareworkers.com with a working example.

Though, now() returns a number and if you are calling split on that you will naturally get that message.

But again, code questions are for mentioned forums, not here I am afraid.

https://cloudflareworkers.com/?_gl=1*eci3h5*_ga*MTAwNDgwMzIyNy4xNjY2MTA2MjUx*_gid*MTcxOTQ3NDQwMi4xNjY3NjQzMDMw#2a243de9dc88a185411b727fde4eb45d:https://tutorial.cloudflareworkers.com

Yeah, that’s not a Cloudflare issue but something with your code, however it might be the previously mentioned type issue.

If you need further assistance please refer to the mentioned forums.

I’ve tested the JS in browser. and it works fine. That’s why asking here instead of StackOverFlow. The code works fine. But somehow the script isn’t getting the value of date to the function the way it should.

See it works if we use normal values ourselves.

https://cloudflareworkers.com/#a21c96f9a48ed51b12098a25f49a2d66:https://tutorial.cloudflareworkers.com

Post a link to jsbin.com with the exact same code working. Should it not be working either, then you owe me a coffee :wink:

1 Like

You were right.

Though, now() returns a number and if you are calling split on that you will naturally get that message.

it returns a number while i needed a string for this to work.

.toString() worked.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.