Home > database >  replace a declared function
replace a declared function

Time:06-10

I have a small code problem:

I want a already declared function to replace it with another one.

For example, let's say i have a js file, with the function:

function SayHello() {
 $(".nav").addClass('sticky animated fadeInDown');
}

and i want to replace that function with another js file and a function like that:

function SayHello() {
 $(".nav").addClass('fadeUp');
}

The code is just an example, but the point is that I can't change the original js, so i want to just replace what the function does.

Any ideas on how i could do that would be appreciated :)

Thanks.

CodePudding user response:

There are two main ways to do this.

One is to include a second function definition later down in a script tag.

The second is to set the new function in the window object

window.sayHello = newFooFunction;

CodePudding user response:

Try this

let MyFunction = function SayHello() {
 return $(".nav").addClass('sticky animated fadeInDown');
}

and if u want to replace it

let MyFunction = function SayHello() {
 return $(".nav").addClass('fadeUp');
}

have a good day

  • Related