官术网_书友最值得收藏!

Callbacks

Luckily, Node creators agreed upon sane conventions on how to structure callbacks early on. It is important to follow this tradition. Deviation leads to surprises, sometimes very bad surprises, and in general, to do so automatically makes an API awkward, a characteristic other developers will rapidly tire of.

One is either returning a function result by executing a callback, handling the arguments received by a callback, or designing the signature for a callback within your API. Whichever situation is being considered, one should follow the convention relevant to that case.

The first argument returned to a callback function is any error message, preferably in the form of an error object. If no error is to be reported, this slot should contain a null value.

When passing a callback to a function, it should be assigned the last slot of the function signature. APIs should be consistently designed this way.

Any number of arguments may exist between the error and the callback slots.

To create an error object: new Error("Argument must be a String!")

主站蜘蛛池模板: 四子王旗| 仲巴县| 驻马店市| 光泽县| 永年县| 固始县| 庆阳市| 顺平县| 宁津县| 治多县| 奉贤区| 外汇| 双牌县| 萝北县| 花莲县| 六安市| 呼玛县| 藁城市| 开远市| 凤阳县| 扶沟县| 葫芦岛市| 忻城县| 锡林郭勒盟| 溧水县| 株洲市| 信宜市| 大方县| 鹤峰县| 临沂市| 枣阳市| 潍坊市| 当涂县| 子长县| 赫章县| 象州县| 兴隆县| 宁城县| 鸡西市| 琼中| 永康市|