Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a javaScript Function

I have a function onChangeBrand() in A.js and there is a same name in B.js.

So how to avoid this situation? There is a constraint - I can't change the function names. and i am not allowed to edit both the Js files so namespace is not a right idea for me.

Can we call something like A.onChangeBrand() or B.onChangeBrand()?

like image 429
BOSS Avatar asked Feb 02 '26 06:02

BOSS


1 Answers

Ok, if namespaces are not for you and you can put your code in between the script tags loading these files

<script src='a.js'></script>
<script>
var a_onChangeBrand = onChangeBrand; // copy the function
</script>
<script src='b.js'></script>

after that a_onChangeBrand() will call the function from a.js and onChangeBrand() from b.js

But nothing will help you if some functions in those a.js and b.js are also using these functions - they might call function from the last file loaded.

like image 70
Cheery Avatar answered Feb 04 '26 01:02

Cheery



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!