我有点卡在一个我无法解决的问题上,我在互联网和这个网站上进行了调查,但我找不到问题的答案。
所以基本上我有一个 javascript 文件,我不能修改它,所以我有另一个 javascript 文件,它应该在调用时捕获该方法并覆盖它。
通常我知道它是如何工作的,我已经完成了功能覆盖,但我不知道如何解决这个问题。
我有一个很大的脚本,但我只展示其中的一小部分:
Microsoft.Office.Server.Ajax.NavResizer.prototype = {
$6: null,
$7: null,
......
$20:function ($p0) {
if (this.$1E) {
$p0.preventDefault();
}
},
$21: function ($p0) {
var $0 = $p0.target;
this.$1F = ($0 === this.$A);
if (this.$1F || $0 === this.$B) {
this.$1E = $0;
this.$18 = $p0.clientX;
this.$19 = $p0.clientY;
Sys.UI.DomEvent.removeHandler(this.$1E, 'mousedown', this.$12);
var $1 = document.body; Sys.UI.DomEvent.addHandler($1, 'mouseup', this.$13);
Sys.UI.DomEvent.addHandler($1, 'mousemove', this.$14);
$1.style.cursor = (this.$1F) ? 'e-resize' : 'n-resize';
this.$1A = this.get_$42();
this.$1B = this.get_$43();
$1.focus();
Sys.UI.DomEvent.addHandler($1, 'selectstart', this.$15);
$p0.preventDefault();
}
},
$22: function ($p0) {
this.$34($p0);
var $0 = document.body;
Sys.UI.DomEvent.removeHandler($0, 'mouseup', this.$13);
Sys.UI.DomEvent.removeHandler($0, 'mousemove', this.$14);
Sys.UI.DomEvent.addHandler($0, 'selectstart', this.$15);
$0.style.cursor = 'default';
Sys.UI.DomEvent.addHandler(this.$1E, 'mousedown', this.$12);
this.$1E = null;
},
$23: function ($p0) {
this.$34($p0);
},
$24: function ($p0) {
this.$26();
},
....
基本上这是脚本的一部分:假设我想在另一个 javascript 文件的脚本中覆盖函数:$22: function ($p0),我该怎么做?
如有任何帮助,我将不胜感激。
一个小更新,提供了一些很好的例子,但它们不起作用。 我运行这个 sript 的环境是 SharePoint,通常当我覆盖时我使用这个方法:
var oldFixRibbonAndWorkspaceDimensions = window.FixRibbonAndWorkspaceDimensions;
window.FixRibbonAndWorkspaceDimensions = function () {
this.MyFixRibbonAndWorkspaceDimensions();
};
function MyFixRibbonAndWorkspaceDimensions(){...}
当我加载脚本时并不重要,因为这个函数只在默认函数被调用时被调用,而不是之前而不是之后。就在同一时间。但是对于此处提供的示例,该函数试图在 document.ready() 上执行
最佳答案
您想永久覆盖它吗?只需这样做:
Microsoft.Office.Server.Ajax.NavResizer.prototype.$22 = function($p0) {
// your code.
};
只要您的脚本在原始定义后执行,就可以了。
关于javascript - 覆盖复杂原型(prototype)javascript中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12859618/