Scutto
Scutto

Reputation: 35

I need to overwrite a run-time function js

i need to overwrite a function that I take from a script, the function start like this:

(function (K) {
//code
})(window);

for a normal function it's easy:

function nameFun = function (params) {
//code
}

so now , how I can overwrite that function ?

Thank you

Upvotes: 3

Views: 176

Answers (2)

Ivan Velichko
Ivan Velichko

Reputation: 6709

If this function is written in separate js file, which is includes on page within <script src="..."> tag, you can try to place inline js code just after this tag and remove it programmatically.

If not, you can simply wrap this code block in try { ... } catch (e) { console.log(e); }.

Upvotes: 0

Ian
Ian

Reputation: 34489

I don't believe you can - it's an anonymous function that is immediately invoked, so it won't be stored on any object for you to overwrite. Even if it were stored somewhere, as it is invoked immediately you're not going to be able to overwrite the function with your own code before it's execution.

Upvotes: 3

Related Questions