小编art*_*iak的帖子

在节点js中设置超时故障

我有一个域异常处理程序(用于夜间测试的包装器).

我的异常处理程序包装器

var domainError = function(func) {

    return function() {
      var d = domain.create().on('error', function(err) {
        console.error(err.stack);
      });

      d.enter();
      try {
        return func.apply(this, arguments);
      }
      catch (err) {
        //do something with the err
      }
      d.exit();
    }
};
Run Code Online (Sandbox Code Playgroud)

我试图设置超时,这样return func.apply(this, arguments);就不会永远.

任何人都可以建议我如何添加超时并使域结束该功能并退出,如果超过超时?

javascript exception-handling settimeout node.js

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

attachShadow vs createShadowRoot

我在mozilla doc中读到,不推荐使用Element.createShadowRoot():

不推荐使用此方法,而使用attachShadow.

但在我的金丝雀:铬49.0.2599.0

这工作:

 var shadow = document.getElementById("node-sh").createShadowRoot();  
Run Code Online (Sandbox Code Playgroud)

这不起作用

 var shadow = document.getElementById("node-sh").attachShadow({mode: 'closed'});
Run Code Online (Sandbox Code Playgroud)

谁知道什么是对的?

shadow-dom

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

AngularJS将服务注入多个控制器

我在自己的模块中定义了一个服务:

angular.module('foteDatasetsService', [])
  .factory('foteAPIservice', function($http) {

    var foteAPI = {};

    foteAPI.getDatasets = function() {
      return $http({
        method: 'JSONP',
        url: 'http://localhost:8080/datasets?callback=JSON_CALLBACK'
      });
    }

    return foteAPI;
  });
Run Code Online (Sandbox Code Playgroud)

在另一个模块中,(在另一个文件中)我有一个控制器,我想用它:

angular.module('foteRequests').controller('foteRequestsController',
  ['$scope', function foteRequestsController($scope, foteAPIservice) {

    //snip other stuff

    $scope.datasets = [];

    foteAPIservice.getDatasets().success(function (response) {
      //Digging into the response to get the relevant data
      $scope.datasets = response;
      console.log(response);
    });

]);
Run Code Online (Sandbox Code Playgroud)

我在一个名为init .js 的文件中有一个init模块,它包含如下依赖项:

'use strict';

angular.module('foteRequests', ['foteDatasetsService']);
Run Code Online (Sandbox Code Playgroud)

它看起来并不像实际上将foteDatasetsService注入控制器.如果我运行该应用程序,我收到一个错误:

Cannot call method 'getDatasets' of undefined
Run Code Online (Sandbox Code Playgroud)

因此,如果我通过在控制器中包含foteDatasetsService来强制解决问题,如下所示:

angular.module('foteRequests').controller('foteRequestsController', ['$scope',
'foteDatasetsService', function foteRequestsController($scope, foteAPIservice) {
... …
Run Code Online (Sandbox Code Playgroud)

dependency-injection angularjs

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

如何过滤另一个数组中的数组

假设我有一个这样的数组:

[
  {
    name:"1",
    args: [1,2,3,4,5]
  },
  {
    name:"2",
    args: [2,3,4,5,6]
  }
]
Run Code Online (Sandbox Code Playgroud)

我想要做的是删除所有值 < 4 的“参数”,得到以下结果:

[
  {
    name:"1",
    args: [4,5]
  },
  {
    name:"2",
    args: [4,5,6]
  }
]
Run Code Online (Sandbox Code Playgroud)

我如何使用 Observables (Rxjs) 做到这一点。我尝试使用mergeMap,但它似乎确实可以满足我的需求。

javascript arrays observable rxjs

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