Questions tagged «side-effect»

2
Array的“每个”或“某些”副作用是否有害?
我一直被教导,在某种if情况下产生副作用是不好的。我的意思是; if (conditionThenHandle()) { // do effectively nothing } ...而不是 if (condition()) { handle(); } ...我知道,我的同事很高兴,因为我不这样做,我们每个星期五的17:00回家,每个人都有一个快乐的周末。 现在,ECMAScript5推出类似的方法every(),并some()到Array了,我发现它们非常有用。他们是清洁比for (;;;)的,再给你一个范围,并且使元素由变量访问。 但是,在验证输入时,我经常发现自己在条件中使用every/ some来验证输入,然后再次在正文中使用every/ 将输入转换为可用模型。some if (input.every(function (that) { return typeof that === "number"; })) { input.every(function (that) { // Model.findById(that); etc } } else { return; } ...当我想做的是 if (!input.every(function (that) { var …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.