如何覆盖另一个javascript文件中的函数? [英] How to override a function in another javascript file?

查看:131
本文介绍了如何覆盖另一个javascript文件中的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JavaScript文件, Mybasefile.js ,其函数为 Mybasefunction()。我想在另一个JavaScript文件中覆盖此函数。在按钮单击中调用该函数时,我希望原始 Mybasefunction()与其他一些代码一起执行。我该怎么做?

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?

推荐答案

将此代码放在覆盖文件中。确保在原始文件之后包含覆盖文件。

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();
    ...
}

这篇关于如何覆盖另一个javascript文件中的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆