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

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!")

主站蜘蛛池模板: 鲁山县| 鄄城县| 利川市| 望江县| 揭阳市| 怀集县| 临沧市| 沙田区| 湟中县| 儋州市| 梁平县| 资源县| 仙桃市| 嵊泗县| 望江县| 宁夏| 镇赉县| 多伦县| 霍城县| 綦江县| 平阴县| 米泉市| 大竹县| 呼玛县| 万载县| 龙井市| 万全县| 江口县| 清新县| 安平县| 华宁县| 突泉县| 遂川县| 延安市| 迁安市| 武陟县| 吉隆县| 伊宁县| 元江| 鹤庆县| 大名县|