惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
U
Unit 42
Google DeepMind News
Google DeepMind News
博客园 - 司徒正美
Y
Y Combinator Blog
F
Fortinet All Blogs
云风的 BLOG
云风的 BLOG
T
Tailwind CSS Blog
G
Google Developers Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MyScale Blog
MyScale Blog
N
Netflix TechBlog - Medium
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
P
Proofpoint News Feed
Jina AI
Jina AI
B
Blog RSS Feed
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志
D
Docker

博客园 - 彷徨......

轻巧地,我走了 Unable to load print control in ReportingService reporting service报表设计时候页面宽度高度的设置 -转 Beginning SQL Server 2005 Reporting Services Sharepoint Server与Reporting Services整合配置 -转 T61装win2003后的驱动安装 一篇绝好的讲sql server索引的文章,值得收藏 使用Div自动换行一事 一个检查SPN的小工具 Create many user to ducumentum contentserver "Personalize" property is invalid in moss2010 - 彷徨...... 这个破备案制度 可恶的小偷 转:HowTo: Deploy .NET ActiveX Control SEO工具大全-转 使用metablog迁移博客园的文章 - 彷徨...... - 博客园 dsa XmlDocument的Load方法报“hexadecimal value .., is an invalid character” - 彷徨...... 出来了没有呢?
How to overwrite the method in Javascript
彷徨...... · 2010-07-06 · via 博客园 - 彷徨......

我最近在做的一个产品是嵌入在MOSS之中,但自2007开始就发现微软其中一些javascript函数写的有问题或者是不符合我们的需求,为此,我们需要覆盖这些native函数。

譬如有一个native方法叫mtd1,如果要覆盖它,主要的做法是使用 window.mtd1 = function { ... your logic .... };  但有时候为了某些需求,微软的js文件加载时间会比我们自己的晚,这样其实我们并不能正常的覆盖这个函数。 此问题的解决方法是使用

window.setTimeout(function()
    {
      window.mtd1 = function { ... your logic .... };
    }, 100);

上边的100是个时间(毫秒),实际使用时候会发现该时间并不好控制,会根据网络情况、机器情况而不同,也能设太大了,以免执行过晚。

依然有解决办法,看一下示例

function setOverrideFunction()
{
 if(window.mtd1!= null)
 {
   window.mtd1 = function { ... your logic .... };
 }
 else
 {
   window.setTimeout(function()
   {
      setOverrideFunction()
   },100);
 }
}

window.setTimeout(function()
    {
      setOverrideFunction();
    }, 100);

OK,完美解决....