2016-01-04 Jason Liao
Glad you back @Drake React.Component or React.createClass 刚刚学习 React 的时候,有很多教程创建一个 React 组件的时候,都是使用 React.createClass,那是 ES6 还没有广泛使用的时候的语法,后来在 React v0.13 的时候,就可以使用 ES6 的 class 来创建 React 组件,也就是继承 React.Component。 继续阅读 »
2014-03-25 W.Y.
在凌乱的异步编程一文中,我们见识了用回调处理异步调用的尴尬局面,即使是一组简单的函数调用。 快速回顾一下,看看我们最初的代码,使用回调函数时的凌乱结果,以及我们为了回到正途而想要解决的几个问题: 我们再也不能使用简单的“调用 - 返回”(call-and-return)编程模型 我们再也不能使用 try/catch/finally 来处理异常 我们必须为可能执行异步操作的每个函数的签名增加 callback 和 errback 参数 1. Promises 一个 Promise(或者叫 Future, Delayed value, Deferred value)代表一个尚不可用的值,因为产生这个值的计算过程尚未完成。一个 Pr 继续阅读 »
2014-03-25 W.Y.
正如我们在凌乱的异步编程一文中看到的那样,基于回调函数的异步代码的错误处理也很快变得混乱起来,丢失了许多同步代码具有的优秀品质,使我们更难定位到错误原因。在用 Promises 简化异步编程一文中,我们介绍了 Promises,看到了它如何使我们回到“调用 - 返回”编程模型,允许异步错误像同步错误那样沿着调用堆栈向上传播,并提供一种更清晰方法来管理异步,特别是在处理错误时。 1. Try/catch/finally 在同步代码中,try/catch/finally 提供了一种简单友好但非常强大的惯用语法来执行任务、处理错误,并且总是确保稍后可以执行清理。 译注:idiom 习语 下面是一个简单的 try/catch/fin 继续阅读 »
2014-03-25 W.Y.
1. 异常和 try/catch 当执行可能失败的操作时,采用异常机制和 try/catch 是一种直观的方式,这样我们就可以从异常中恢复,或将异常抛出,异常沿着调用堆栈到达调用者,调用者可以处理该异常或将其继续抛出。 看一个简单的例子: ```javascript function thisMightFail() { //... if(badThingsHappened) { throw new Error(...); } return theGoodResult; } function recoverFromFailure(e) { //... return re 继续阅读 »
2014-03-25 W.Y.
在 JavaScript 中处理异步和回调就是家常便饭,我们通常会面对这样一些问题: 1. 如何优雅滴组织我们的回调代码 2. 对异步函数错误处理的最佳实践是什么 3. 异步嵌套问题 4. 怎样使我们的代码可读性和可维护性更高 Programs are meant to be read by humans and only incidentally for computers to execute. 程序是给人读的,只是顺带让计算机执行一下。 ——《编写可维护的JavaScript》@Donald Knuth 当然,最常见也是最简单的处理方式就是,直接将回调函数或错误处理函数作为异步函数的参数,在异步函数返回时进行相应的调用,这 继续阅读 »
2014-12-12 林长宇
How To Use the Widget Factory To start, we'll create a progress bar that just lets us set the progress once. As we can see below, this is done by calling jQuery.widget() with two parameters: the name of the plugin to create, and an object literal containing functions to support our plugin. When our plugin gets called, 继续阅读 »
2015-02-24 YongHao Hu
QNAN wiki上是这样说的: A QNaN is a NaN with the most significant fraction bit set. QNaN’s propagate freely through most arithmetic operations. These values pop out of an operation when the result is not mathematically defined. (details)[http://en.wikipedia.org/wiki/NaN] 我尝试过sqrt(-1), 1/0, NAN/NAN都不行 结果: 继续阅读 »
2015-02-04 veryyoung
今天突然想用markdown写博文,这样应该会方便不少。 开工 1.下载插件。 这里我选择了Markdown QuickTags 在官网看到 !This plugin hasn't been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress. 有点被惊呆 2.启用插件 下载完该插件之后,放入WordPress的plugins文件夹下,上传代码,然后再后台启用即 继续阅读 »
2014-08-08 Kun Ren
(This post is rewritten to adapt to the latest release of pipeR) Pipeline is receiving increasing attention in R community these days. It is hard to tell when it begins but more people start to use it since the easy-and-fast dplyr package imports the magic operator %>% from magrittr, the pioneer package of pipeline op 继续阅读 »
2015-12-01 Klaus Ma
Summary The default value is helpful when using enum in protobuf; but there're some tips I'd like to highlight here: 继续阅读 »