小编005*_*005的帖子

Class.prototype.method vs this.prototype.method

我一直看到Class.prototype.method的例子,但从来没有看过this.prototype.method的例子.例如:

function Class() {
    this.prototype.method = function() {
        alert("is this allowed?");
    };
}
Run Code Online (Sandbox Code Playgroud)

VS

function Class() {}
Class.prototype.method = function() {
    alert("traditional example");
};
Run Code Online (Sandbox Code Playgroud)
  1. this.prototype存在吗?
  2. 它与Class.prototype相同吗?
  3. 继承怎么样?

javascript prototype

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

为什么在Redux中单独执行动作+ reducers?

我已经看到了分离行动和减少者的论点,因为他们有多对多的关系.

我不认为这实际上适用于Redux.因为只有1个数据存储区,所以对reducer的操作应该是1对多.

通常,reducer适用于特定数据存储的特​​定更改.

MY_ACTION = "MY_ACTION"
function reducer(state, action) {
    switch(action.type) {
        case MY_ACTION: // stuff with my action to create new state
        default: return state
    }
}
Run Code Online (Sandbox Code Playgroud)

我们可以组合多个reducer,combineReducers为什么不为动作本身定义动作的处理程序.

例如

class Action {
    constructor(type) {
        this.type = type
        this.handlers = []
    }
    add_handler(handler) {
        this.handlers += handler
    }
    get_reducer() {
        reducer = combineReducers(this.handlers)
        return (state, action) => {
            if(action.type == this.type) {
                return reducer(state, action)
            }
            return state
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

使用"ducks"模式,我们最终将主减速器放在与动作声明相同的模块中.

是否有任何理由将reducer + actions与redux分开?

redux

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

Java是否具有可索引的多队列线程池?

是否存在以下Java类:

  1. 可执行任务可以通过id添加,其中具有相同id的所有任务都保证不会同时运行
  2. 线程数可以限制为固定数量

一个朴素的Map解决方案很容易解决(1),但很难管理(2).类似地,我所知道的所有线程池类都将从单个队列中拉出,这意味着(1)不能保证.

欢迎涉及外部库的解决方案.

java queue multithreading threadpool

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

将 Spring Bean 的可访问范围 (@Autowire/@Resource) 限制为包

如何限制 Spring bean 的可访问范围?

这可能吗,或者推荐吗?


我问,因为我有一个情况,我想ConnectionManager为每个特定的类提供一个类(以防我以后需要单独的类)。@Autowired @ResourceIExternalConnectionConnectionManager

但是,我不希望其他类直接使用这些连接。对我来说,有某种方法将 beans 包设为私有是有意义的IExternalConnection

关于 Spring Bean 范围的大多数问题都与 的生命周期有关Bean,这不是这个问题的重点

编辑: 这里有一些代码片段来澄清我的意思

public class ConnectionFactory {
    @Resource(name = "defaultConnectionManager")
    private IExternalConnectionManager              defaultConnectionManager;

    @Resource(name = "someOtherConnectionManager")
    private IExternalConnectionManager              someOtherConnectionManager;
}
Run Code Online (Sandbox Code Playgroud)

配置类:

@Configuration
public class Connections {
    @Bean
    public ConnectionFactory defaultConnectionFactory() {
        return new ConnectionFactory();
    }
    @Bean
    public IExternalConnectionManager defaultConnectionManager() {
        return new defaultConnectionManager();
    }
    @Bean
    public IExternalConnectionManager someOtherConnectionManager() {
        return new someOtherConnectionManager();
    }
}
Run Code Online (Sandbox Code Playgroud)

目标是 …

spring

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

add_column中使用的Alembic默认值

如何使Alembic为新列使用指定的默认值,而不将其设置为server_default

仅现有行应接收此默认值。插入后的新行仍应获取server_default

sqlalchemy alembic

5
推荐指数
2
解决办法
1778
查看次数

防止git删除未跟踪的.gitignored文件?

我问,因为git stash -u开始删除我的.gitignored eclipse配置设置,并没有将它们保存到存储中.我完全丢失了我的项目配置.(如果这不是正确或预期的行为,请告诉我)

还有哪些其他命令可以删除未跟踪,忽略的文件?

有哪些有效的预防措施可以确保未删除未跟踪的本地文件?


编辑 - 补充资料:

混帐藏匿

如果要保留.gitignored文件,请使用--all而不是-u.

[-u | --include-未跟踪]

如果--include-未经跟踪选项时,所有未跟踪的文件也被藏匿,然后清理与git的干净,留下的工作目录中一个非常干净的状态.如果使用--all选项,则除了未跟踪的文件之外,还会隐藏和清除被忽略的文件.

git

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

with 语句中的 Python 交互式 REPL

从 python 交互式会话中,有没有办法在 with 语句中输入 REPL 循环?

通常, with 语句作为单个块执行

>>>
>>> with app.app_context():
>>> ...   # Normally this is executed as a single block, all at once
Run Code Online (Sandbox Code Playgroud)

我希望能够在上下文中的交互式会话中运行代码。

>>>
>>> with app.app_context():
>>> # do stuff here in a REPL loop
Run Code Online (Sandbox Code Playgroud)

python ipython python-3.x

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

Ansible 使用带有 blockinfile 的模板

blockinfile似乎用{{模板做基本的替换。该文档没有提到任何模板功能。

但是,似乎不可能做一个完整的模板,比如循环。这失败了template error while templating string: unexpected '%'

  blockinfile:
    dest: /etc/haproxy/haproxy.cfg
    marker: "# {mark} ANSIBLE CONFIG certs"
    block: |
      {% if certs %}
      bind *:443 ssl crt {% for cert in certs %}{{cert}} {{% endfor %}
      {% endif %}
Run Code Online (Sandbox Code Playgroud)

这似乎是一个基本用例,我可能想对配置文件进行一次性编辑,但仍然需要模板的强大功能。

请注意, usingwith_items在这里并没有真正做到我想要的,因为我只需要 1 行。

jinja2 ansible-playbook ansible-2.x

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