gpt4 book ai didi

javascript - 覆盖有参数的js函数

转载 作者:行者123 更新时间:2023-11-28 05:25:58 25 4
gpt4 key购买 nike

我想覆盖有参数的js方法。

请检查原始js文件:bundle.js

Product.Bundle = Class.create();
Product.Bundle.prototype = {
reloadPrice: function() {

----- Default Code -----

},
selectionPrice: function(optionId, selectionId) {

----- Default Code -----
},
}

我必须覆盖 js 文件中的这两个方法。我可以成功覆盖我的js中的reloadPrice方法,但无法覆盖selectionPrice方法。

请检查我的js文件代码,其中reloadPrice方法被成功覆盖

<script>
Product.Bundle.prototype.reloadPrice =
Product.Bundle.prototype.reloadPrice.wrap(function(parentMethod) {
----- Default Code ------
});


// Doing same thnig for SelectionPrice method but not worked :
Product.Bundle.prototype.selectionPrice =
Product.Bundle.prototype.selectionPrice.wrap(function(parentMethod) {
----- Default Code -----
});
</script>

我哪里错了,请帮助我。

最佳答案

当您必须覆盖具有参数的方法时,您可以像下面这样覆盖它:

<script>
Product.Bundle.prototype.selectionPrice =
Product.Bundle.prototype.selectionPrice.wrap(function(parentMethod,optionId, selectionId) {
----- Default Code -----
});
</script>

关于javascript - 覆盖有参数的js函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40168512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com