小编Dan*_*lev的帖子

如何为所有Backbone模型添加默认错误处理程序?

背景:

Backbone模型提供了一个注册回退错误处理程序的选项,每次调用服务器失败并且没有提供特定的处理程序时,都会调用该处理程序.

MyModel = new Backbone.Model.extend({
  initialize: function(option) {
    this.on("error", this.fallbackErrorHandler);
  },

  fallbackErrorHandler: function() {
    // default behavior in case of an error
  },

  foo: function() {
    this.fetch();             // fallbackErrorHandler will be called
    this.fetch({              // the inline error handler will be called
      error: function() {
        // some specific code for this error
      }
    });
  }    
});
Run Code Online (Sandbox Code Playgroud)

我想做的事:

我希望我的应用程序中的所有主干模型都有一个回退错误处理程序.但是 - 我不想为每个模型显式添加处理程序. 我想定义并注册一次处理程序,并将其应用于我的应用程序中的每个主干模型.另外,我不想更改现有代码,也不想改变开发人员在我的应用程序中定义Models的方式.

我已经尝试过的:

我添加了一个初始化程序,它在Backbone.Model.prototype对象上注册一个处理程序.

App.Marionette.addInitializer(function() {
  Backbone.Model.prototype.on("error",function(){
     // default behavior in case of an error
  }); …
Run Code Online (Sandbox Code Playgroud)

backbone.js backbone-events

11
推荐指数
1
解决办法
4931
查看次数

使用 Cucumber 运行时如何添加 RunListener 和 TestExecutionListeners

我们当前的测试框架使用junit + spring + selenium 运行。我们的测试同时使用了 junit 的org.junit.runner.notification.RunListeners 和 spring org.springframework.test.context.TestExecutionListener

这是测试定义的样子:

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners(listeners = {MyTestExecutionListener.class})
@ContextConfiguration(locations = {"classpath:/META-INF/spring/my-context.xml"})
public abstract class BaseAutomationTest extends AbstractJUnit4SpringContextTests {
}
Run Code Online (Sandbox Code Playgroud)

我的问题是在使用 Cucumber 时我应该在哪里编写驻留在侦听器中的代码

请注意,此代码需要访问 spring 的ApplicationContext.

junit cucumber-jvm cucumber-junit spring-junit

5
推荐指数
0
解决办法
835
查看次数

当方法具有相同名称的参数时,访问闭包变量

请考虑以下代码:

function() {
  var a = "Hello World";

  function foo(a) {
    alert(a);
  }
}
Run Code Online (Sandbox Code Playgroud)

这将打印传递给的值foo.

如何访问a闭包中定义的变量,以便打印"Hello World"?

javascript

1
推荐指数
1
解决办法
42
查看次数