很好的 ECMAScript 2015 包装 CasperJS 方法的方法。

Good ECMAScript 2015 way to wrap method of CasperJS.

使用 CasperJS begin 测试方法 属性 的 casper 对象我想做这样的事情:

casper.test.begin=(function(originalMethod) {
    return function() {
        // some custom logic here. 
        originalMethod.call(this, arguments);
    }
}(casper.test.begin));

但我希望它以正确的 ECMA 2015 方式实现(我使用 babel)。 我试图继承 CasperJS,但我遇到了一堆问题。 如果有任何意见、想法和建议,我将不胜感激。

你想使用 Facade(又名包装器)吗?

class MyFacade {

  constructor(legacyLibrary) {
    this.legacyLibrary = legacyLibrary;
  }

  newMethod() {
    this.legacyLibrary.doSomething();
    this.legacyLibrary.doSomethingElse();
  }

}

export default MyFacade;

因此,您只需传递现有 class 的实例,然后做任何您想做的事,而不是猴子修补它。