我有一个模块如下:
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();
})
最佳答案
您可以使用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/