gpt4 book ai didi

javascript - 是否可以在没有目标的方法上使用 dojo 方面?

转载 作者:行者123 更新时间:2023-12-02 15:59:56 27 4
gpt4 key购买 nike

我有一个模块如下:

define([...], function(...){
function anothermethod() {...}
function request() {....}
request.anothermethod = anothermethod;
return request;
}

现在我想在请求方法(闭包)的anothermethod方法上使用dojo方面。是否可以?如果是这样,我应该在目标参数中输入什么?

aspect.before(target, methodName, advisingFunction);

并且另一个方法不是直接调用的。首先调用请求方法,该方法间接调用另一个方法:

require(['dojo/aspect'], function(aspect){
function anothermethod() {
console.log('another method');
}
function beforeanothermethod() {
console.log('before another method');
}
function request() {
anothermethod();
}
request.anothermethod = anothermethod;
aspect.before(request, 'anothermethod', beforeanothermethod);
request();
})

https://jsfiddle.net/ahwgw5tb/1/

最佳答案

您可以使用request作为目标。请参阅:

require(['dojo/aspect'], function(aspect){
function anothermethod() {
console.log('another method');
}
function beforeanothermethod() {
console.log('before another method');
}

function request() {}
request.anothermethod = anothermethod;

aspect.before(request, 'anothermethod', beforeanothermethod)

request.anothermethod();
})
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>

关于javascript - 是否可以在没有目标的方法上使用 dojo 方面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31281529/

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