我有一个 View 和 Utility 类,并希望在 View 的工作完成后加入 Utility 方法。所以想要在 View 的渲染调用完成后调用实用程序方法(向视图添加行为)。
使用 ES6 代理 API,有没有办法在执行方法之前/之后执行main
方法?(又名方法拦截)
类似于 YUI3 Do API。 http://yuilibrary.com/yui/docs/api/classes/Do.html
我有一个 View 和 Utility 类,并希望在 View 的工作完成后加入 Utility 方法。所以想要在 View 的渲染调用完成后调用实用程序方法(向视图添加行为)。
使用 ES6 代理 API,有没有办法在执行方法之前/之后执行main
方法?(又名方法拦截)
类似于 YUI3 Do API。 http://yuilibrary.com/yui/docs/api/classes/Do.html
Yes there is a way. Actually I'm trying to build the same thing and as long as you use a synchronous context I already got it working. Have a look at the code examples in the issue I created for my problem: stack overflow when returning an ES6 proxy through a promise
What you need to do to intercept the call is to use the ES6 proxy to get notified of the get
-call that takes place to retrieve the function before the method is actually called.
In my example you can see that you get all the information about the call like what method was called with which parameters and also who called it and on which target it was originally called.