-4

sorta like jquery but I wanna make a function in js with a .whatever at the end, for example function().text() or something like that what I've tried to do is

function a() {

    function click() {
        alert("hi");
    }
}
Username 2020
  • 101
  • 2
  • 10

1 Answers1

0

"function" is a reserved word so you can't use that as a function name. You could create a function with a different name such as "foo". It needs to return an object with the key "whatever" which is another function that you can call and do something with.

For example:

function foobar (){
 const foo = {}
    foo.whatever = function (){
     console.log('foobar')
    }
    return foo
}


foobar().whatever()