(JS、jQuery 和 jqTree 的新手)
我正在尝试在另一个(我自己的)中覆盖一个 .js 文件(tree.jquery.js)中的方法(JqTreeWidget.prototype.openNode
)。custom.js
我读过它来覆盖一般的 js 方法,我只需要重新定义它。所以我试图在方法上做到这一点,我想我被困在访问具有原始方法( JqTreeWidget
)的变量上。我认为挑战在于原始方法位于(源)中,它与我想要进行覆盖tree.jquery.js
的我自己的其他文件分开。custom.js
这个问题的目标是让我在我的(将是这个问题的答案)中写出这样的东西:custom.js
<reference to JqTreeWidget.prototype.openNode>
var originalMethod = <reference to JqTreeWidget.prototype.openNode>;
// Override of originalMethod
<reference to JqTreeWidget.prototype.openNode> = function( node, slide ){
// my code I want to happen 1st here
changeAncestorHeightRecursively( node, true);
// my code is done, and now I'm ready to call the original method
originalMethod.call( this, node, slide );
}
我认为这将是进行覆盖的最非侵入性的方式,而无需实际侵入tree.jquery.js
源代码。
看我的custom.js
的http://codepen.io/cellepo/pen/LGoaQxtree.jquery.js
在该 codepen 的 JS 设置中从外部添加
单独的源。
如何(从我的custom.js
文件中)访问JqTreeWidget
源文件 ( ) 中的变量tree.jquery.js
? 甚至可能吗?不在JqTreeWidget
范围之外tree.jquery.js
,还是不是全局变量?本来希望treeContainer.tree.prototype
有的,可惜到现在还没有运气。。。
谢谢!