如何使用 dojo 方面调用常规 JavaScript 函数
How to call a regular JavaScript function using dojo aspect
我在 dojo 方面提到了 JavaScript 对象中的一个方法,例如
aspect.before(objectname, "someMethod", function(arg1, arg2) {
console.warn("aspect.before: ", arg1, arg2);
});
是否可以像
那样调用常规的JavaScript函数
function cn(){
alert("Hello");
}
道场方面
这或多或少是以下内容的重复:is it possible to use dojo aspect on a method with no target?
在你的情况下,你必须使用 window
对象:
function aMethod() {
console.log('the method');
}
require(['dojo/aspect'], function(aspect) {
aspect.before(window, 'aMethod', function() {
console.log('this runs before');
});
});
aMethod();
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
我在 dojo 方面提到了 JavaScript 对象中的一个方法,例如
aspect.before(objectname, "someMethod", function(arg1, arg2) {
console.warn("aspect.before: ", arg1, arg2);
});
是否可以像
那样调用常规的JavaScript函数 function cn(){
alert("Hello");
}
道场方面
这或多或少是以下内容的重复:is it possible to use dojo aspect on a method with no target?
在你的情况下,你必须使用 window
对象:
function aMethod() {
console.log('the method');
}
require(['dojo/aspect'], function(aspect) {
aspect.before(window, 'aMethod', function() {
console.log('this runs before');
});
});
aMethod();
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>