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

标签 javascript dojo

我有一个模块如下:

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/

相关文章:

javascript - jQuery 验证插件 : Email validation only happens on blur

javascript - 为什么 Javascript 不能在 digital.Dialog 弹出窗口中工作?

javascript - 如何在不在 dojo.ready 中声明它的代码的情况下编写我的小部件

javascript - ajax调用后表消失了

javascript - 在 Node.JS 中禁用日志记录

jquery - ajax 请求后重新加载 dojo 小部件

javascript - 任何只有一个 API 同时支持桌面和移动设备的 Javascript 框架?

node.js - Dojo - request.get - .Uncaught TypeError : request. get(...).then(...).catch 不是函数

javascript - Angular Material Slider 渲染不正确

javascript - JSX 中的虚假值 react