I have a JavaScript file, Mybasefile.js
, which has the function Mybasefunction()
. I want to override this function in another JavaScript file. When the function is called in a button click, I want the original Mybasefunction()
to be executed along with some other code. How can I do this?
Unlike the other programming languages, JavaScript Does not support Function Overloading.
To override a method, we give it the same name and parameters as the method in the superclass. We can override receiveDamage() from the superclass by coding the same method in the subclass.
TypeScript in version 4.3 introduced the override keyword which allows you to explicitly state that you intend to override a method from a base class.
Since ECMAScript 6 (or ES6) you can use the export or import statement in a JavaScript file to export or import variables, functions, classes or any other entity to/from other JS files.
place this code in the override file. Make sure the override file is included after the orginal one.
var orig_Mybasefunction = window.Mybasefunction;
window.Mybasefunction = function(){
orig_Mybasefunction();
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With